use of uk.gov.gchq.gaffer.serialisation.Serialiser in project gaffer-doc by gchq.
the class PropertiesWalkthrough method listToBytesSerialisers.
protected boolean listToBytesSerialisers(final Class<?> clazz) {
final List<Class> toBytesSerialiserClasses = new ArrayList<>();
for (final Serialiser serialise : TO_BYTES_SERIALISERS) {
if (serialise.canHandle(clazz)) {
toBytesSerialiserClasses.add(serialise.getClass());
}
}
if (toBytesSerialiserClasses.contains(JavaSerialiser.class)) {
if (toBytesSerialiserClasses.contains(AvroSerialiser.class)) {
if (toBytesSerialiserClasses.size() > 2) {
toBytesSerialiserClasses.remove(JavaSerialiser.class);
toBytesSerialiserClasses.remove(AvroSerialiser.class);
}
} else {
if (toBytesSerialiserClasses.size() > 1) {
toBytesSerialiserClasses.remove(JavaSerialiser.class);
}
}
} else if (toBytesSerialiserClasses.contains(AvroSerialiser.class)) {
if (toBytesSerialiserClasses.size() > 1) {
toBytesSerialiserClasses.remove(AvroSerialiser.class);
}
}
final List<String> toBytesSerialiserClassNames = new ArrayList<>();
for (final Class toBytesSerialiserClass : toBytesSerialiserClasses) {
toBytesSerialiserClassNames.add(WalkthroughStrSubstitutor.getJavaDocLink(toBytesSerialiserClass, false));
}
if (!toBytesSerialiserClasses.isEmpty()) {
print(SERIALISERS_KEY, "\nTo Bytes Serialisers:");
print(SERIALISERS_KEY, "\n- " + StringUtils.join(toBytesSerialiserClassNames, "\n- "));
}
return !toBytesSerialiserClasses.isEmpty();
}
use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.
the class MultiSerialiserStorage method canHandle.
/**
* @param handleClass class to check
* @return {@link ToBytesSerialiser#canHandle(Class)}
* @see ToBytesSerialiser
*/
public boolean canHandle(final Class handleClass) {
boolean rtn = false;
final Byte key = classToKey.get(handleClass);
if (null != key) {
Serialiser serialiser = keyToSerialiser.get(key);
rtn = null != serialiser && serialiser.canHandle(handleClass);
}
return rtn;
}
use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.
the class SchemaTest method shouldBuildSchema.
@Test
public void shouldBuildSchema() {
// Given
final Serialiser vertexSerialiser = mock(Serialiser.class);
// When
final Schema schema = new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition()).entity(TestGroups.ENTITY, new SchemaEntityDefinition()).entity(TestGroups.ENTITY_2, new SchemaEntityDefinition()).edge(TestGroups.EDGE_2, new SchemaEdgeDefinition()).vertexSerialiser(vertexSerialiser).type(TestTypes.PROP_STRING, String.class).visibilityProperty(TestPropertyNames.VISIBILITY).config("key", "value").build();
// Then
assertEquals(2, schema.getEdges().size());
assertNotNull(schema.getEdge(TestGroups.EDGE));
assertNotNull(schema.getEdge(TestGroups.EDGE_2));
assertEquals(2, schema.getEntities().size());
assertNotNull(schema.getEntity(TestGroups.ENTITY));
assertNotNull(schema.getEntity(TestGroups.ENTITY_2));
assertEquals(String.class, schema.getType(TestTypes.PROP_STRING).getClazz());
assertSame(vertexSerialiser, schema.getVertexSerialiser());
assertEquals(TestPropertyNames.VISIBILITY, schema.getVisibilityProperty());
assertEquals("value", schema.getConfig("key"));
}
use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.
the class SchemaTest method shouldThrowExceptionWhenMergeSchemasWithConflictingVertexSerialiser.
@Test
public void shouldThrowExceptionWhenMergeSchemasWithConflictingVertexSerialiser() {
// Given
final Serialiser vertexSerialiser1 = new StringSerialiser();
final Serialiser vertexSerialiser2 = new StringToStringSerialiser();
final Schema schema1 = new Schema.Builder().vertexSerialiser(vertexSerialiser1).build();
final Schema schema2 = new Schema.Builder().vertexSerialiser(vertexSerialiser2).build();
// When / Then
assertThatExceptionOfType(SchemaException.class).isThrownBy(() -> new Schema.Builder().merge(schema1).merge(schema2).build()).withMessageContaining("vertex serialiser");
}
use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.
the class AccumuloSerialisationFactoryTest method shouldReturnCustomSerialiserForCustomClass.
@Test
public void shouldReturnCustomSerialiserForCustomClass() throws SerialisationException {
// Given
final SerialisationFactory factory = new AccumuloSerialisationFactory();
final Class<?> clazz = HyperLogLogPlus.class;
// When
final Serialiser serialiser = factory.getSerialiser(clazz);
// Then
assertTrue(serialiser.canHandle(clazz));
assertEquals(HyperLogLogPlusSerialiser.class, serialiser.getClass());
}
Aggregations