本文整理汇总了Java中uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator类的典型用法代码示例。如果您正苦于以下问题:Java TupleAdaptedBinaryOperator类的具体用法?Java TupleAdaptedBinaryOperator怎么用?Java TupleAdaptedBinaryOperator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TupleAdaptedBinaryOperator类属于uk.gov.gchq.koryphe.tuple.binaryoperator包,在下文中一共展示了TupleAdaptedBinaryOperator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldJsonSerialiseAndDeserialise
import uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator; //导入依赖的package包/类
@Test
public void shouldJsonSerialiseAndDeserialise() throws IOException {
TupleAdaptedBinaryOperator<String, Integer> binaryOperator = new TupleAdaptedBinaryOperator<>();
MockBinaryOperator function = new MockBinaryOperator();
TupleInputAdapter<String, Integer> inputAdapter = new TupleInputAdapter();
binaryOperator.setInputAdapter(inputAdapter);
binaryOperator.setBinaryOperator(function);
String json = JsonSerialiser.serialise(binaryOperator);
TupleAdaptedBinaryOperator<String, Integer> deserialisedBinaryOperator = JsonSerialiser.deserialise(json, TupleAdaptedBinaryOperator.class);
// check deserialisation
assertNotSame(binaryOperator, deserialisedBinaryOperator);
BinaryOperator<Integer> deserialisedFunction = deserialisedBinaryOperator.getBinaryOperator();
assertNotSame(function, deserialisedFunction);
assertTrue(deserialisedFunction instanceof MockBinaryOperator);
Function<Tuple<String>, Integer> deserialisedInputMask = deserialisedBinaryOperator.getInputAdapter();
assertNotSame(inputAdapter, deserialisedInputMask);
assertTrue(deserialisedInputMask instanceof Function);
}
示例2: shouldReturnUnmodifiableComponentsWhenLocked
import uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator; //导入依赖的package包/类
@Test
public void shouldReturnUnmodifiableComponentsWhenLocked() {
// Given
final ElementAggregator aggregator = new ElementAggregator();
// When
aggregator.lock();
final List<TupleAdaptedBinaryOperator<String, ?>> components = aggregator.getComponents();
// Then
try {
components.add(null);
fail("Exception expected");
} catch (final UnsupportedOperationException e) {
assertNotNull(e);
}
}
示例3: validateFunctionArgumentTypes
import uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator; //导入依赖的package包/类
protected ValidationResult validateFunctionArgumentTypes(
final ElementAggregator aggregator,
final SchemaElementDefinition schemaElDef) {
final ValidationResult result = new ValidationResult();
if (null != aggregator && null != aggregator.getComponents()) {
for (final TupleAdaptedBinaryOperator<String, ?> adaptedFunction : aggregator.getComponents()) {
if (null == adaptedFunction.getBinaryOperator()) {
result.addError(aggregator.getClass().getSimpleName() + " contains a null function.");
} else {
final Signature inputSig = Signature.getInputSignature(adaptedFunction.getBinaryOperator());
result.add(inputSig.assignable(getTypeClasses(adaptedFunction.getSelection(), schemaElDef)));
final Signature outputSig = Signature.getOutputSignature(adaptedFunction.getBinaryOperator());
result.add(outputSig.assignable(getTypeClasses(adaptedFunction.getSelection(), schemaElDef)));
}
}
}
return result;
}
示例4: validateFunctionArgumentTypes
import uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator; //导入依赖的package包/类
private ValidationResult validateFunctionArgumentTypes(
final ElementAggregator aggregator,
final ViewElementDefinition viewElDef, final SchemaElementDefinition schemaElDef) {
final ValidationResult result = new ValidationResult();
if (null != aggregator && null != aggregator.getComponents()) {
for (final TupleAdaptedBinaryOperator<String, ?> adaptedFunction : aggregator.getComponents()) {
if (null == adaptedFunction.getBinaryOperator()) {
result.addError(aggregator.getClass().getSimpleName() + " contains a null function.");
} else {
final Class[] inputTypeClasses = getTypeClasses(adaptedFunction.getSelection(), viewElDef, schemaElDef);
if (!ArrayUtils.contains(inputTypeClasses, null)) {
final Signature inputSig = Signature.getInputSignature(adaptedFunction.getBinaryOperator());
result.add(inputSig.assignable(inputTypeClasses));
}
}
}
}
return result;
}
示例5: testTupleAggregation
import uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator; //导入依赖的package包/类
@Test
public void testTupleAggregation() {
String[] inputs = new String[]{"input1", "input2", "input3"};
String[] outputs = new String[]{"output1", "output2", "output3"};
TupleAdaptedBinaryOperator<String, String> binaryOperator = new TupleAdaptedBinaryOperator<>();
Tuple<String>[] tuples = new Tuple[]{mock(Tuple.class), mock(Tuple.class), mock(Tuple.class)};
// set up the function
BinaryOperator<String> function = mock(BinaryOperator.class);
TupleInputAdapter<String, String> inputAdapter = mock(TupleInputAdapter.class);
TupleOutputAdapter<String, String> outputAdapter = mock(TupleOutputAdapter.class);
binaryOperator.setBinaryOperator(function);
binaryOperator.setInputAdapter(inputAdapter);
binaryOperator.setOutputAdapter(outputAdapter);
Tuple<String> state = tuples[0];
for (int i = 1; i < tuples.length; i++) {
given(inputAdapter.apply(tuples[i])).willReturn(inputs[i]);
given(inputAdapter.apply(state)).willReturn(outputs[i - 1]);
given(function.apply(outputs[i - 1], inputs[i])).willReturn(outputs[i]);
given(outputAdapter.apply(state, outputs[i])).willReturn(state);
state = binaryOperator.apply(state, tuples[i]);
}
// check the expected calls
for (int i = 1; i < tuples.length; i++) {
verify(inputAdapter, times(1)).apply(tuples[i]);
String in1 = outputs[i - 1];
String in2 = inputs[i];
verify(function, times(1)).apply(in1, in2);
verify(inputAdapter, times(1)).apply(tuples[i]);
verify(outputAdapter, times(1)).apply(tuples[0], outputs[i]);
}
verify(inputAdapter, times(2)).apply(tuples[0]);
}
示例6: getBinaryOperator
import uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator; //导入依赖的package包/类
@Override
public BinaryOperator<Tuple<String>> getBinaryOperator() {
TupleAdaptedBinaryOperator<String, Number> binaryOperator = new TupleAdaptedBinaryOperator<>();
binaryOperator.setBinaryOperator(new Product());
binaryOperator.setSelection(new String[]{"A"});
return binaryOperator;
}
示例7: getComponents
import uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator; //导入依赖的package包/类
@Override
public List<TupleAdaptedBinaryOperator<String, ?>> getComponents() {
if (readOnly) {
return Collections.unmodifiableList(super.getComponents());
}
return super.getComponents();
}
示例8: shouldReturnModifiableComponentsWhenNotLocked
import uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator; //导入依赖的package包/类
@Test
public void shouldReturnModifiableComponentsWhenNotLocked() {
// Given
final ElementAggregator aggregator = new ElementAggregator();
// When
final List<TupleAdaptedBinaryOperator<String, ?>> components = aggregator.getComponents();
// Then - no exceptions
components.add(null);
}
示例9: validateElementAggregator
import uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator; //导入依赖的package包/类
private ValidationResult validateElementAggregator(final Map.Entry<String, ?> entry, final Schema schema) {
final ValidationResult result = new ValidationResult();
List<TupleAdaptedBinaryOperator<String, ?>> aggregateFunctions = new ArrayList<>();
final SchemaElementDefinition schemaElement = schema.getElement(entry.getKey());
if (null != schemaElement) {
aggregateFunctions = schemaElement.getOriginalAggregateFunctions();
}
List<BinaryOperator<?>> schemaOperators = new ArrayList<>();
if (null != aggregateFunctions) {
schemaOperators = Streams.toStream(aggregateFunctions)
.map(AdaptedBinaryOperator::getBinaryOperator)
.collect(Collectors.toList());
}
if (schemaOperators.contains(null)) {
result.addError("Schema contains an ElementAggregator with a null function.");
}
final AggregatePair pair = (AggregatePair) entry.getValue();
final ElementAggregator aggregator = pair.getElementAggregator();
if (null != aggregator && null != aggregator.getComponents()) {
for (final TupleAdaptedBinaryOperator<String, ?> adaptedFunction : aggregator.getComponents()) {
if (null == adaptedFunction.getBinaryOperator()) {
result.addError(aggregator.getClass().getSimpleName() + " contains a null function.");
}
}
}
return result;
}
示例10: validateAggregatePropertyClasses
import uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator; //导入依赖的package包/类
/**
* Validates that the binary operators to be executed are assignable to the corresponding non-transient properties
*
* @param elementDef The SchemaElementDefinition to validate against
* @param pair AggregatePair, containing a String array of groupBy properties, and an ElementAggregator
* @return ValidationResult of the validation
*/
private ValidationResult validateAggregatePropertyClasses(final SchemaElementDefinition elementDef, final AggregatePair pair) {
final ValidationResult result = new ValidationResult();
if (null != elementDef) {
final ElementAggregator aggregator = pair.getElementAggregator();
if (null != aggregator) {
final List<TupleAdaptedBinaryOperator<String, ?>> components = aggregator.getComponents();
for (final TupleAdaptedBinaryOperator<String, ?> component : components) {
final String[] selection = component.getSelection();
final Class[] selectionClasses = Arrays.stream(selection).map(elementDef::getPropertyClass).toArray(Class[]::new);
final Map<String, String> properties = elementDef.getPropertyMap();
if (!properties.isEmpty()) {
if (null == component.getBinaryOperator()) {
result.addError(aggregator.getClass().getSimpleName() + " contains a null function.");
}
for (int i = 0; i < selectionClasses.length; i++) {
if (properties.containsKey(selection[i])) {
final Signature inputSig = Signature.getInputSignature(component.getBinaryOperator());
result.add(inputSig.assignable(selectionClasses[i]));
}
}
}
}
}
}
return result;
}
示例11: getIngestAggregator
import uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator; //导入依赖的package包/类
@JsonIgnore
public ElementAggregator getIngestAggregator() {
if (null == ingestAggregatorCache) {
ingestAggregatorCache = new ElementAggregator();
if (aggregate) {
final Set<String> aggregatorProperties = getAggregatorProperties();
if (null != aggregator) {
for (final TupleAdaptedBinaryOperator<String, ?> component : aggregator.getComponents()) {
final String[] selection = component.getSelection();
if (selection.length == 1 && !groupBy.contains(selection[0]) && !selection[0].equals(schemaReference.getVisibilityProperty())) {
ingestAggregatorCache.getComponents().add(component);
} else if (!CollectionUtil.containsAny(groupBy, selection)) {
ingestAggregatorCache.getComponents().add(component);
}
}
}
for (final Entry<String, String> entry : getPropertyMap().entrySet()) {
if (!aggregatorProperties.contains(entry.getKey())) {
if (!groupBy.contains(entry.getKey()) && !entry.getKey().equals(schemaReference.getVisibilityProperty())) {
addTypeAggregateFunction(ingestAggregatorCache, entry.getKey(), entry.getValue());
}
}
}
}
ingestAggregatorCache.lock();
}
return ingestAggregatorCache;
}
示例12: getAggregatorProperties
import uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator; //导入依赖的package包/类
private Set<String> getAggregatorProperties() {
if (null == propertiesInAggregatorCache) {
if (null == aggregator) {
propertiesInAggregatorCache = Collections.emptySet();
} else {
propertiesInAggregatorCache = new HashSet<>();
for (final TupleAdaptedBinaryOperator<String, ?> component : aggregator.getComponents()) {
Collections.addAll(propertiesInAggregatorCache, component.getSelection());
}
}
}
return propertiesInAggregatorCache;
}
示例13: select
import uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator; //导入依赖的package包/类
public SelectedBuilder select(final String... selection) {
final TupleAdaptedBinaryOperator<String, Object> current = new TupleAdaptedBinaryOperator<>();
current.setSelection(selection);
return new SelectedBuilder(aggregator, current);
}
示例14: SelectedBuilder
import uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator; //导入依赖的package包/类
private SelectedBuilder(final ElementAggregator aggregator, final TupleAdaptedBinaryOperator<String, Object> current) {
this.aggregator = aggregator;
this.current = current;
}
示例15: shouldBuildAggregator
import uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator; //导入依赖的package包/类
@Test
public void shouldBuildAggregator() {
// Given
final String property1 = "property 1";
final String property2a = "property 2a";
final String property2b = "property 2b";
final String property3 = "property 3";
final BinaryOperator func1 = mock(BinaryOperator.class);
final BinaryOperator func2 = mock(BinaryOperator.class);
final BinaryOperator func3 = mock(BinaryOperator.class);
// When - check you can build the selection/function in any order,
// although normally it will be done - select then execute.
final ElementAggregator aggregator = new ElementAggregator.Builder()
.select(property1)
.execute(func1)
.select(property2a, property2b)
.execute(func2)
.select(property3)
.execute(func3)
.build();
// Then
int i = 0;
TupleAdaptedBinaryOperator<String, ?> adaptedFunction = aggregator.getComponents().get(i++);
assertEquals(1, adaptedFunction.getSelection().length);
assertEquals(property1, adaptedFunction.getSelection()[0]);
assertSame(func1, adaptedFunction.getBinaryOperator());
adaptedFunction = aggregator.getComponents().get(i++);
assertEquals(2, adaptedFunction.getSelection().length);
assertEquals(property2a, adaptedFunction.getSelection()[0]);
assertEquals(property2b, adaptedFunction.getSelection()[1]);
assertSame(func2, adaptedFunction.getBinaryOperator());
adaptedFunction = aggregator.getComponents().get(i++);
assertSame(func3, adaptedFunction.getBinaryOperator());
assertEquals(1, adaptedFunction.getSelection().length);
assertEquals(property3, adaptedFunction.getSelection()[0]);
assertEquals(i, aggregator.getComponents().size());
}