use of uk.gov.gchq.gaffer.types.TypeSubTypeValue in project Gaffer by gchq.
the class TypeSubTypeValueToTupleTest method shouldConvertTypeSubTypeValueToTuple.
@Test
public void shouldConvertTypeSubTypeValueToTuple() {
// Given
final TypeSubTypeValue typeSubTypeValue = new TypeSubTypeValue("type", "subType", "value");
final TypeSubTypeValueToTuple function = getInstance();
// When
final Tuple<String> result = function.apply(typeSubTypeValue);
// Then
assertEquals("type", result.get("type"));
assertEquals("value", result.get("value"));
}
use of uk.gov.gchq.gaffer.types.TypeSubTypeValue in project Gaffer by gchq.
the class GetElementsTest method shouldDeserialiseOperationWithVerticesAndIds.
@Test
public void shouldDeserialiseOperationWithVerticesAndIds() throws SerialisationException {
// Given
final String json = String.format("{\"class\":\"uk.gov.gchq.gaffer.operation.impl.get.GetElements\"," + "\"input\":[" + "1," + "{\"class\":\"uk.gov.gchq.gaffer.types.TypeSubTypeValue\",\"type\":\"t\",\"subType\":\"s\",\"value\":\"v\"}," + "{\"vertex\":{\"java.lang.Long\":2},\"class\":\"uk.gov.gchq.gaffer.operation.data.EntitySeed\"}" + "]}");
// When
final GetElements deserialisedOp = JSONSerialiser.deserialise(json, GetElements.class);
// Then
assertEquals(Lists.newArrayList(new EntitySeed(1), new EntitySeed(new TypeSubTypeValue("t", "s", "v")), new EntitySeed(2L)), Lists.newArrayList(deserialisedOp.getInput()));
}
use of uk.gov.gchq.gaffer.types.TypeSubTypeValue in project Gaffer by gchq.
the class KeyFunctionMatchTest method shouldMatchObjectsBasedOnKeyFunctions.
@Test
public void shouldMatchObjectsBasedOnKeyFunctions() {
// given
TypeSubTypeValue testValue = new TypeSubTypeValue("myType", "mySubType", "30");
List<Long> testList = Lists.newArrayList(100L, 200L, 300L, 400L);
// when
KeyFunctionMatch match = new KeyFunctionMatch.Builder().firstKeyFunction(new FunctionComposite(Lists.newArrayList(new CallMethod("getValue"), new ToInteger()))).secondKeyFunction(new FunctionComposite(Lists.newArrayList(new ToInteger(), new DivideBy(10), new FirstItem<>()))).build();
match.init(testList);
// then
List<Long> expected = Lists.newArrayList(300L);
assertEquals(expected, match.matching(testValue));
}
use of uk.gov.gchq.gaffer.types.TypeSubTypeValue in project Gaffer by gchq.
the class TypeSubTypeValueSerialiser method deserialise.
@Override
public TypeSubTypeValue deserialise(final byte[] bytes) throws SerialisationException {
int lastDelimiter = 0;
TypeSubTypeValue typeSubTypeValue = new TypeSubTypeValue();
for (int i = 0; i < bytes.length; i++) {
if (bytes[i] == ByteArrayEscapeUtils.DELIMITER) {
if (i > 0) {
try {
typeSubTypeValue.setType(new String(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, i), CommonConstants.UTF_8));
} catch (final UnsupportedEncodingException e) {
throw new SerialisationException("Failed to deserialise the Type from TypeSubTypeValue Object", e);
}
}
lastDelimiter = i + 1;
break;
}
}
for (int i = lastDelimiter; i < bytes.length; i++) {
if (bytes[i] == ByteArrayEscapeUtils.DELIMITER) {
if (i > lastDelimiter) {
try {
typeSubTypeValue.setSubType(new String(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, i), CommonConstants.UTF_8));
} catch (final UnsupportedEncodingException e) {
throw new SerialisationException("Failed to deserialise the SubType from TypeSubTypeValue Object", e);
}
}
lastDelimiter = i + 1;
break;
}
}
if (bytes.length > lastDelimiter) {
try {
typeSubTypeValue.setValue(new String(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, bytes.length), CommonConstants.UTF_8));
} catch (final UnsupportedEncodingException e) {
throw new SerialisationException("Failed to deserialise the Value from TypeSubTypeValue Object", e);
}
}
return typeSubTypeValue;
}
use of uk.gov.gchq.gaffer.types.TypeSubTypeValue in project Gaffer by gchq.
the class GetElementsTest method shouldDeserialiseOperationWithVertices.
@Test
public void shouldDeserialiseOperationWithVertices() throws SerialisationException {
// Given
final String json = "{\"class\":\"uk.gov.gchq.gaffer.operation.impl.get.GetElements\"," + "\"input\":[" + "1," + "{\"class\":\"uk.gov.gchq.gaffer.types.TypeSubTypeValue\",\"type\":\"t\",\"subType\":\"s\",\"value\":\"v\"}," + "[\"java.lang.Long\",2]" + "]}";
// When
final GetElements deserialisedOp = JSONSerialiser.deserialise(json, GetElements.class);
// Then
assertEquals(Lists.newArrayList(new EntitySeed(1), new EntitySeed(new TypeSubTypeValue("t", "s", "v")), new EntitySeed(2L)), Lists.newArrayList(deserialisedOp.getInput()));
}
Aggregations