本文整理汇总了Java中uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate类的典型用法代码示例。如果您正苦于以下问题:Java TupleAdaptedPredicate类的具体用法?Java TupleAdaptedPredicate怎么用?Java TupleAdaptedPredicate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TupleAdaptedPredicate类属于uk.gov.gchq.koryphe.tuple.predicate包,在下文中一共展示了TupleAdaptedPredicate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate; //导入依赖的package包/类
/**
* Apply the predicate components in turn, returning false if any fail the test.
*
* @param input Input value
* @return True if all components pass, otherwise false.
*/
@Override
public boolean test(final I input) {
for (final C predicate : components) {
try {
if (!predicate.test(input)) {
return false;
}
} catch (final ClassCastException e) {
// This may occur if the predicate was given a tuple1 and the tuple1 was automatically unpacked.
if (predicate instanceof TupleAdaptedPredicate && !(input instanceof Tuple)) {
if (!((TupleAdaptedPredicate) predicate).getPredicate().test(input)) {
return false;
}
} else {
throw e;
}
}
}
return true;
}
示例2: test
import uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate; //导入依赖的package包/类
@Override
public boolean test(final I input) {
for (final Predicate<I> predicate : components) {
try {
if (predicate.test(input)) {
return true;
}
} catch (final ClassCastException e) {
// This may occur if the predicate was given a tuple1 and the tuple1 was automatically unpacked.
if (predicate instanceof TupleAdaptedPredicate && !(input instanceof Tuple)) {
if (((TupleAdaptedPredicate) predicate).getPredicate().test(input)) {
return true;
}
} else {
throw e;
}
}
}
return false;
}
示例3: shouldJsonSerialiseAndDeserialise
import uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate; //导入依赖的package包/类
@Test
public void shouldJsonSerialiseAndDeserialise() throws IOException {
// set up a tuple validate
TupleAdaptedPredicate<String, Object> predicate = new TupleAdaptedPredicate<>();
Predicate<Object> function = new MockPredicateObject();
predicate.setPredicate(function);
Function<Tuple<String>, Object> inputAdapter = new TupleInputAdapter<>();
predicate.setInputAdapter(inputAdapter);
String json = JsonSerialiser.serialise(predicate);
TupleAdaptedPredicate<String, Object> deserialisedPredicate = JsonSerialiser.deserialise(json, TupleAdaptedPredicate.class);
assertNotSame(predicate, deserialisedPredicate);
Predicate deserialisedFunction = deserialisedPredicate.getPredicate();
assertNotSame(function, deserialisedFunction);
Function<Tuple<String>, Object> deserialisedInputAdapter = deserialisedPredicate.getInputAdapter();
assertNotSame(inputAdapter, deserialisedInputAdapter);
assertTrue(deserialisedInputAdapter instanceof Function);
}
示例4: addOrFilter
import uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate; //导入依赖的package包/类
private Pair<FilterPredicate, Set<Path>> addOrFilter(final List<Predicate> predicateList,
final String[] selection,
final String group) throws SerialisationException {
Pair<FilterPredicate, Set<Path>> filter = null;
final boolean multiSelection = selection.length > 1;
for (final Predicate functionContext : predicateList) {
final Predicate filterFunction;
final String[] newSelections;
if (functionContext instanceof TupleAdaptedPredicate) {
filterFunction = ((TupleAdaptedPredicate) functionContext).getPredicate();
// Build new selections
final Integer[] ints = (Integer[]) ((TupleAdaptedPredicate) functionContext).getSelection();
newSelections = new String[ints.length];
for (int x = 0; x < ints.length; x++) {
newSelections[x] = selection[ints[x]];
}
} else {
filterFunction = functionContext;
newSelections = selection;
}
filter = orFilter(filter, buildFilter(filterFunction, newSelections, group), multiSelection, group);
}
return filter;
}
示例5: addAndFilter
import uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate; //导入依赖的package包/类
private Pair<FilterPredicate, Set<Path>> addAndFilter(final List<Predicate> predicateList,
final String[] selection,
final String group) throws SerialisationException {
Pair<FilterPredicate, Set<Path>> filter = null;
for (final Predicate functionContext : predicateList) {
final Predicate filterFunction;
final String[] newSelections;
if (functionContext instanceof TupleAdaptedPredicate) {
filterFunction = ((TupleAdaptedPredicate) functionContext).getPredicate();
// Build new selections
final Integer[] ints = (Integer[]) ((TupleAdaptedPredicate) functionContext).getSelection();
newSelections = new String[ints.length];
for (int x = 0; x < ints.length; x++) {
newSelections[x] = selection[ints[x]];
}
} else {
filterFunction = functionContext;
newSelections = selection;
}
filter = andFilter(filter, buildFilter(filterFunction, newSelections, group), selection.length > 1);
}
return filter;
}
示例6: getErrorMsg
import uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate; //导入依赖的package包/类
private String getErrorMsg(final TupleAdaptedPredicate<String, ?> predicate) {
final StringBuilder builder = new StringBuilder();
builder.append("Filter: ")
.append(predicate.getPredicate())
.append(" returned false for properties: {");
boolean firstProp = true;
for (final String selection : predicate.getSelection()) {
final Object value = elementTuple.get(selection);
final String valueStr = null != value ? String.format("<%s>%s", value.getClass().getCanonicalName(), value) : "null";
if (firstProp) {
firstProp = false;
} else {
builder.append(", ");
}
builder.append(selection)
.append(": ")
.append(valueStr);
}
builder.append("}");
return builder.toString();
}
示例7: shouldReturnUnmodifiableComponentsWhenLocked
import uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate; //导入依赖的package包/类
@Test
public void shouldReturnUnmodifiableComponentsWhenLocked() {
// Given
final ElementFilter filter = getTestObject();
// When
filter.lock();
final List<TupleAdaptedPredicate<String, ?>> components = filter.getComponents();
// Then
try {
components.add(null);
fail("Exception expected");
} catch (final UnsupportedOperationException e) {
assertNotNull(e);
}
}
示例8: validateFilterPropertyClasses
import uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate; //导入依赖的package包/类
/**
* Validates that the predicates to be executed are assignable to the corresponding properties
*
* @param elementDef The SchemaElementDefinition to validate against
* @param filter The ElementFilter to be validated against
* @return ValidationResult of the validation
*/
private ValidationResult validateFilterPropertyClasses(final SchemaElementDefinition elementDef, final ElementFilter filter) {
final ValidationResult result = new ValidationResult();
if (null != elementDef) {
final List<TupleAdaptedPredicate<String, ?>> components = filter.getComponents();
for (final TupleAdaptedPredicate<String, ?> component : components) {
final Map<String, String> properties = elementDef.getPropertyMap();
if (!properties.isEmpty()) {
if (null == component.getPredicate()) {
result.addError(filter.getClass().getSimpleName() + " contains a null function.");
} else {
final Class[] selectionClasses = getTypeClasses(component.getSelection(), elementDef);
if (!ArrayUtils.contains(selectionClasses, null)) {
final Signature inputSig = Signature.getInputSignature(component.getPredicate());
result.add(inputSig.assignable(selectionClasses));
}
}
}
}
}
return result;
}
示例9: validateFunctionArgumentTypes
import uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate; //导入依赖的package包/类
protected ValidationResult validateFunctionArgumentTypes(
final ElementFilter filter, final SchemaElementDefinition schemaElDef) {
final ValidationResult result = new ValidationResult();
if (null != filter && null != filter.getComponents()) {
for (final TupleAdaptedPredicate<String, ?> adaptedPredicate : filter.getComponents()) {
if (null == adaptedPredicate.getPredicate()) {
result.addError(filter.getClass().getSimpleName() + " contains a null function.");
} else {
final Signature inputSig = Signature.getInputSignature(adaptedPredicate.getPredicate());
result.add(inputSig.assignable(getTypeClasses(adaptedPredicate.getSelection(), schemaElDef)));
}
}
}
return result;
}
示例10: validateFunctionArgumentTypes
import uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate; //导入依赖的package包/类
private ValidationResult validateFunctionArgumentTypes(
final ElementFilter filter,
final ViewElementDefinition viewElDef, final SchemaElementDefinition schemaElDef) {
final ValidationResult result = new ValidationResult();
if (null != filter && null != filter.getComponents()) {
for (final TupleAdaptedPredicate<String, ?> adaptedPredicate : filter.getComponents()) {
if (null == adaptedPredicate.getPredicate()) {
result.addError(filter.getClass().getSimpleName() + " contains a null function.");
} else {
final Class[] inputTypeClasses = getTypeClasses(adaptedPredicate.getSelection(), viewElDef, schemaElDef);
if (!ArrayUtils.contains(inputTypeClasses, null)) {
final Signature inputSig = Signature.getInputSignature(adaptedPredicate.getPredicate());
result.add(inputSig.assignable(inputTypeClasses));
}
}
}
}
return result;
}
示例11: testSingleFunctionTransformation
import uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate; //导入依赖的package包/类
@Test
public void testSingleFunctionTransformation() {
String input = "input";
TupleAdaptedPredicate<String, String> predicate = new TupleAdaptedPredicate<>();
Function<Tuple<String>, String> inputAdapter = mock(Function.class);
predicate.setInputAdapter(inputAdapter);
Predicate<String> function = mock(Predicate.class);
predicate.setPredicate(function);
Tuple<String> tuple = mock(Tuple.class);
// set up mocks
given(inputAdapter.apply(tuple)).willReturn(input);
given(function.test(input)).willReturn(true);
// validate
assertTrue(predicate.test(tuple));
// function should have been tested
verify(inputAdapter, times(1)).apply(tuple);
verify(function, times(1)).test(input);
// switch to fail
given(function.test(input)).willReturn(false);
// and try again
assertFalse(predicate.test(tuple));
// function should have been tested again
verify(inputAdapter, times(2)).apply(tuple);
verify(function, times(2)).test(input);
}
示例12: getPredicate
import uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate; //导入依赖的package包/类
@Override
public Predicate<Tuple<String>> getPredicate() {
TupleAdaptedPredicate<String, Comparable> tupleIsMoreThan = new TupleAdaptedPredicate<>();
tupleIsMoreThan.setSelection(new String[]{"A"});
tupleIsMoreThan.setPredicate(new IsMoreThan(2));
TupleAdaptedPredicate<String, Comparable> tupleIsLessThan = new TupleAdaptedPredicate<>();
tupleIsLessThan.setSelection(new String[]{"C"});
tupleIsLessThan.setPredicate(new IsLessThan(8));
return new And<>(Arrays.asList(tupleIsMoreThan, tupleIsLessThan));
}
示例13: buildGroupValidatorFilter
import uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate; //导入依赖的package包/类
protected Pair<FilterPredicate, Set<Path>> buildGroupValidatorFilter(final String group) throws SerialisationException {
Pair<FilterPredicate, Set<Path>> groupFilter = null;
final SchemaElementDefinition schemaElementDefinition = schemaUtils.getGafferSchema().getElement(group);
final List<TupleAdaptedPredicate<String, ?>> validationFunctions = schemaElementDefinition.getValidator(false).getComponents();
if (null != validationFunctions) {
for (final TupleAdaptedPredicate<String, ?> filterFunctionContext : validationFunctions) {
final Pair<FilterPredicate, Set<Path>> filter = buildFilter(filterFunctionContext.getPredicate(), filterFunctionContext.getSelection(), group);
groupFilter = andFilter(groupFilter, filter, filterFunctionContext.getSelection().length > 1);
}
}
return groupFilter;
}
示例14: buildGroupFilter
import uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate; //导入依赖的package包/类
/**
* Builds up the filter to be applied to the given group's files based on the pre-aggregation view filters.
* This method handles the group level looping over all filters for that group in the view
*
* @param group a Gaffer group
* @param isEntity is the gaffer group an Entity group
* @return The Parquet filter based on the provided groups pre-aggregation view filters
* @throws SerialisationException If any of the Gaffer objects are unable to be serialised to Parquet objects
*/
protected Pair<FilterPredicate, Set<Path>> buildGroupFilter(final String group, final boolean isEntity) throws SerialisationException {
Pair<FilterPredicate, Set<Path>> groupFilter = null;
final ViewElementDefinition groupView = view.getElement(group);
if (null != groupView) {
List<TupleAdaptedPredicate<String, ?>> preAggFilterFunctions = groupView.getPreAggregationFilterFunctions();
if (null != preAggFilterFunctions) {
for (final TupleAdaptedPredicate<String, ?> filterFunctionContext : preAggFilterFunctions) {
final Pair<FilterPredicate, Set<Path>> filter = buildFilter(filterFunctionContext.getPredicate(), filterFunctionContext.getSelection(), group);
groupFilter = andFilter(groupFilter, filter, filterFunctionContext.getSelection().length > 1);
}
}
}
if (!isEntity) {
final FilterPredicate directedFilter;
if (directedType == DirectedType.DIRECTED) {
directedFilter = eq(booleanColumn(ParquetStoreConstants.DIRECTED), true);
} else if (directedType == DirectedType.UNDIRECTED) {
directedFilter = eq(booleanColumn(ParquetStoreConstants.DIRECTED), false);
} else {
directedFilter = null;
}
if (null != groupFilter && null != directedFilter) {
groupFilter = new Pair<>(and(groupFilter.getFirst(), directedFilter), groupFilter.getSecond());
} else if (null == groupFilter && (null != directedFilter || needsValidatorsAndFiltersApplying)) {
groupFilter = new Pair<>(directedFilter, getAllPathsForColumn(group));
}
}
final Pair<FilterPredicate, Set<Path>> groupValidationFilter = buildGroupValidatorFilter(group);
if (null != groupFilter && null != groupValidationFilter) {
return new Pair<>(andFilter(groupFilter.getFirst(), buildGroupValidatorFilter(group).getFirst()), groupFilter.getSecond());
} else if (null != groupFilter) {
return groupFilter;
} else {
return groupValidationFilter;
}
}
示例15: getComponents
import uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate; //导入依赖的package包/类
@Override
public List<TupleAdaptedPredicate<String, ?>> getComponents() {
if (readOnly) {
return Collections.unmodifiableList(super.getComponents());
}
return super.getComponents();
}