Added OR search operator to the Grid with "|", fixes #1759

This commit is contained in:
raoulvdberge
2018-04-27 01:23:01 +02:00
parent 24ff8d5bd3
commit 510595a6bc
4 changed files with 61 additions and 12 deletions

View File

@@ -3,6 +3,7 @@
### 1.5.34 ### 1.5.34
- Allow crafters to be daisy-chained (tomKPZ) - Allow crafters to be daisy-chained (tomKPZ)
- Empty patterns can no longer be inserted in the pattern result slot in the Pattern Grid with hoppers (raoulvdberge) - Empty patterns can no longer be inserted in the pattern result slot in the Pattern Grid with hoppers (raoulvdberge)
- Added OR search operator to the Grid with "|" (raoulvdberge)
### 1.5.33 ### 1.5.33
- Added Crafter Manager (raoulvdberge) - Added Crafter Manager (raoulvdberge)

View File

@@ -104,8 +104,8 @@ public class NetworkNodeGrid extends NetworkNode implements IGridNetworkAware {
// Allow in slot 0 // Allow in slot 0
// Disallow in slot 1 // Disallow in slot 1
// Only allow in slot 1 when it isn't a blank pattern // Only allow in slot 1 when it isn't a blank pattern
// This makes it so that written patterns can be re-inserted in the slot to be overwritten again // This makes it so that written patterns can be re-inserted in slot 1 to be overwritten again
// This makes it so that blank patterns can't be inserted through hoppers. // This makes it so that blank patterns can't be inserted in slot 1 through hoppers.
if (slot == 0 || stack.getTagCompound() != null) { if (slot == 0 || stack.getTagCompound() != null) {
return super.insertItem(slot, stack, simulate); return super.insertItem(slot, stack, simulate);
} }

View File

@@ -0,0 +1,27 @@
package com.raoulvdberge.refinedstorage.gui.grid.filtering;
import com.raoulvdberge.refinedstorage.gui.grid.stack.IGridStack;
import java.util.List;
import java.util.function.Predicate;
public class GridFilterOr implements Predicate<IGridStack> {
private List<List<Predicate<IGridStack>>> orPartFilters;
public GridFilterOr(List<List<Predicate<IGridStack>>> orPartFilters) {
this.orPartFilters = orPartFilters;
}
@Override
public boolean test(IGridStack gridStack) {
for (List<Predicate<IGridStack>> orPart : orPartFilters) {
for (Predicate<IGridStack> part : orPart) {
if (part.test(gridStack)) {
return true;
}
}
}
return false;
}
}

View File

@@ -11,18 +11,21 @@ import java.util.function.Predicate;
public final class GridFilterParser { public final class GridFilterParser {
public static List<Predicate<IGridStack>> getFilters(@Nullable IGrid grid, String query, List<IFilter> filters) { public static List<Predicate<IGridStack>> getFilters(@Nullable IGrid grid, String query, List<IFilter> filters) {
List<Predicate<IGridStack>> gridFilters = new LinkedList<>(); List<Predicate<IGridStack>> gridFilters;
for (String part : query.toLowerCase().trim().split(" ")) { String[] orParts = query.split("\\|");
if (part.startsWith("@")) {
gridFilters.add(new GridFilterMod(part.substring(1))); if (orParts.length == 1) {
} else if (part.startsWith("#")) { gridFilters = getFilters(query);
gridFilters.add(new GridFilterTooltip(part.substring(1)));
} else if (part.startsWith("$")) {
gridFilters.add(new GridFilterOreDict(part.substring(1)));
} else { } else {
gridFilters.add(new GridFilterName(part)); List<List<Predicate<IGridStack>>> orPartFilters = new LinkedList<>();
for (String orPart : orParts) {
orPartFilters.add(getFilters(orPart));
} }
gridFilters = new LinkedList<>();
gridFilters.add(new GridFilterOr(orPartFilters));
} }
if (grid != null) { if (grid != null) {
@@ -39,4 +42,22 @@ public final class GridFilterParser {
return gridFilters; return gridFilters;
} }
private static List<Predicate<IGridStack>> getFilters(String query) {
List<Predicate<IGridStack>> gridFilters = new LinkedList<>();
for (String part : query.toLowerCase().trim().split(" ")) {
if (part.startsWith("@")) {
gridFilters.add(new GridFilterMod(part.substring(1)));
} else if (part.startsWith("#")) {
gridFilters.add(new GridFilterTooltip(part.substring(1)));
} else if (part.startsWith("$")) {
gridFilters.add(new GridFilterOreDict(part.substring(1)));
} else {
gridFilters.add(new GridFilterName(part));
}
}
return gridFilters;
}
} }