Search in sources :

Example 11 with Serialiser

use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.

the class SerialisationFactoryTest method shouldReturnSerialiserForAString.

@Test
public void shouldReturnSerialiserForAString() throws SerialisationException {
    // Given
    final SerialisationFactory factory = new SerialisationFactory();
    final Class<?> clazz = String.class;
    // When
    final Serialiser serialiser = factory.getSerialiser(clazz);
    // Then
    assertTrue(serialiser.canHandle(clazz));
    assertEquals(StringSerialiser.class, serialiser.getClass());
}
Also used : Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) RawDoubleSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDoubleSerialiser) OrderedIntegerSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.ordered.OrderedIntegerSerialiser) RawDateSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDateSerialiser) JavaSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser) BooleanSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.BooleanSerialiser) RawFloatSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawFloatSerialiser) Test(org.junit.jupiter.api.Test)

Example 12 with Serialiser

use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.

the class SerialisationFactoryTest method shouldReturnOrderedSerialiserForAString.

@Test
public void shouldReturnOrderedSerialiserForAString() throws SerialisationException {
    // Given
    final SerialisationFactory factory = new SerialisationFactory();
    final Class<?> clazz = String.class;
    final boolean ordered = true;
    // When
    final Serialiser serialiser = factory.getSerialiser(clazz, ordered, true);
    // Then
    assertTrue(serialiser.canHandle(clazz));
    assertEquals(StringSerialiser.class, serialiser.getClass());
}
Also used : Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) RawDoubleSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDoubleSerialiser) OrderedIntegerSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.ordered.OrderedIntegerSerialiser) RawDateSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDateSerialiser) JavaSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser) BooleanSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.BooleanSerialiser) RawFloatSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawFloatSerialiser) Test(org.junit.jupiter.api.Test)

Example 13 with Serialiser

use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.

the class SerialisationFactoryTest method shouldReturnSerialiserForAnInteger.

@Test
public void shouldReturnSerialiserForAnInteger() throws SerialisationException {
    // Given
    final SerialisationFactory factory = new SerialisationFactory();
    final Class<?> clazz = Integer.class;
    // When
    final Serialiser serialiser = factory.getSerialiser(clazz);
    // Then
    assertTrue(serialiser.canHandle(clazz));
    assertEquals(OrderedIntegerSerialiser.class, serialiser.getClass());
}
Also used : Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) RawDoubleSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDoubleSerialiser) OrderedIntegerSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.ordered.OrderedIntegerSerialiser) RawDateSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDateSerialiser) JavaSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser) BooleanSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.BooleanSerialiser) RawFloatSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawFloatSerialiser) Test(org.junit.jupiter.api.Test)

Example 14 with Serialiser

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, 3));
    }
    if (!toBytesSerialiserClasses.isEmpty()) {
        print(SERIALISERS_KEY, "\nTo Bytes Serialisers:");
        print(SERIALISERS_KEY, "\n- " + StringUtils.join(toBytesSerialiserClassNames, "\n- "));
    }
    return !toBytesSerialiserClasses.isEmpty();
}
Also used : Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) JavaSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser) ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) AvroSerialiser(uk.gov.gchq.gaffer.serialisation.AvroSerialiser) ArrayList(java.util.ArrayList) AvroSerialiser(uk.gov.gchq.gaffer.serialisation.AvroSerialiser)

Example 15 with Serialiser

use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.

the class SchemaTest method shouldMergeDifferentSchemas.

@Test
public void shouldMergeDifferentSchemas() {
    // Given
    final String typeShared = "typeShared";
    final String type1 = "type1";
    final String type2 = "type2";
    final Serialiser vertexSerialiser = new StringSerialiser();
    final Schema schema1 = new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_1, type1).build()).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.COUNT, typeShared).build()).vertexSerialiser(vertexSerialiser).type(typeShared, Long.class).type(type1, Integer.class).visibilityProperty(TestPropertyNames.VISIBILITY).config("key1a", "value1a").config("key1b", "value1b").build();
    final Schema schema2 = new Schema.Builder().entity(TestGroups.ENTITY_2, new SchemaEntityDefinition.Builder().property(TestPropertyNames.COUNT, typeShared).build()).edge(TestGroups.EDGE_2, new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_2, type2).build()).type(type2, String.class).type(typeShared, Long.class).config("key1b", "value1c").config("key2", "value2").build();
    // When
    final Schema mergedSchema = new Schema.Builder().merge(schema1).merge(schema1).merge(schema2).merge(// should be able to merge a duplicate schema
    schema2).build();
    // Then
    assertEquals(2, mergedSchema.getEdges().size());
    assertEquals(1, mergedSchema.getEdge(TestGroups.EDGE).getPropertyMap().size());
    assertEquals(type1, mergedSchema.getEdge(TestGroups.EDGE).getPropertyMap().get(TestPropertyNames.PROP_1));
    assertEquals(1, mergedSchema.getEdge(TestGroups.EDGE_2).getPropertyMap().size());
    assertEquals(type2, mergedSchema.getEdge(TestGroups.EDGE_2).getPropertyMap().get(TestPropertyNames.PROP_2));
    assertEquals(2, mergedSchema.getEntities().size());
    assertEquals(1, mergedSchema.getEntity(TestGroups.ENTITY).getPropertyMap().size());
    assertEquals(typeShared, mergedSchema.getEntity(TestGroups.ENTITY).getPropertyMap().get(TestPropertyNames.COUNT));
    assertEquals(1, mergedSchema.getEntity(TestGroups.ENTITY_2).getPropertyMap().size());
    assertEquals(typeShared, mergedSchema.getEntity(TestGroups.ENTITY_2).getPropertyMap().get(TestPropertyNames.COUNT));
    assertEquals(Integer.class, mergedSchema.getType(type1).getClazz());
    assertEquals(String.class, mergedSchema.getType(type2).getClazz());
    assertEquals(vertexSerialiser, mergedSchema.getVertexSerialiser());
    assertEquals(TestPropertyNames.VISIBILITY, mergedSchema.getVisibilityProperty());
    assertEquals("value1a", mergedSchema.getConfig("key1a"));
    assertEquals("value1c", mergedSchema.getConfig("key1b"));
    assertEquals("value2", mergedSchema.getConfig("key2"));
}
Also used : StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) StringToStringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.tostring.StringToStringSerialiser) RawLongSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawLongSerialiser) MapSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.MapSerialiser) Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) JavaSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser) ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) StringToStringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.tostring.StringToStringSerialiser) Test(org.junit.jupiter.api.Test)

Aggregations

Serialiser (uk.gov.gchq.gaffer.serialisation.Serialiser)28 Test (org.junit.jupiter.api.Test)18 JavaSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser)18 StringSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser)16 ToBytesSerialiser (uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser)10 BooleanSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.BooleanSerialiser)8 OrderedIntegerSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.ordered.OrderedIntegerSerialiser)8 RawDateSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDateSerialiser)8 RawDoubleSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDoubleSerialiser)8 RawFloatSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.raw.RawFloatSerialiser)8 StringToStringSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.tostring.StringToStringSerialiser)6 MapSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.MapSerialiser)5 RawLongSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.raw.RawLongSerialiser)5 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)4 Schema (uk.gov.gchq.gaffer.store.schema.Schema)4 ArrayList (java.util.ArrayList)3 JSONSerialiser (uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser)3 AvroSerialiser (uk.gov.gchq.gaffer.serialisation.AvroSerialiser)3 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)3 HyperLogLogPlus (com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)2