Tabnine Logo
TypeValue
Code IndexAdd Tabnine to your IDE (free)

How to use
TypeValue
in
uk.gov.gchq.gaffer.types

Best Java code snippets using uk.gov.gchq.gaffer.types.TypeValue (Showing top 20 results out of 315)

origin: gchq/Gaffer

@Test
public void testCanSerialiseDeSerialiseCorrectlyTypeOnly() throws SerialisationException {
  TypeValue typeValue = new TypeValue();
  typeValue.setType("testType");
  byte[] bytes = serialiser.serialise(typeValue);
  String serialisedForm = new String(bytes);
  assertEquals("testType\0", serialisedForm);
  TypeValue deSerialisedTypeValue = serialiser.deserialise(bytes);
  assertEquals(typeValue.getType(), deSerialisedTypeValue.getType());
  assertNull(typeValue.getValue(), deSerialisedTypeValue.getValue());
  assertEquals(typeValue, deSerialisedTypeValue);
}
origin: gchq/Gaffer

@Test
public void testCanSerialiseDeSerialiseCorrectlyValueOnly() throws SerialisationException {
  TypeValue typeValue = new TypeValue();
  typeValue.setValue("testValue");
  byte[] bytes = serialiser.serialise(typeValue);
  String serialisedForm = new String(bytes);
  assertEquals("\0testValue", serialisedForm);
  TypeValue deSerialisedTypeValue = serialiser.deserialise(bytes);
  assertNull(deSerialisedTypeValue.getType());
  assertEquals(typeValue.getValue(), deSerialisedTypeValue.getValue());
  assertEquals(typeValue, deSerialisedTypeValue);
}
origin: gchq/Gaffer

@Test
public void testComparisonsAreAsExpected() {
  TypeValue typeValue = new TypeValue("a", "b");
  assertEquals(0, typeValue.compareTo(new TypeValue("a", "b")));
  assertTrue(typeValue.compareTo(null) > 0);
  assertTrue(typeValue.compareTo(new TypeValue()) > 0);
  assertTrue(typeValue.compareTo(new TypeValue("1", "b")) > 0);
  assertTrue(typeValue.compareTo(new TypeValue("a", "a")) > 0);
  assertTrue(typeValue.compareTo(new TypeValue("b", "a")) < 0);
  assertTrue(typeValue.compareTo(new TypeValue("a", "c")) < 0);
}
origin: gchq/Gaffer

  @Override
  public int compareTo(final TypeValue typeValue) {
    if (null == typeValue) {
      return 1;
    }
    int i = stringComparator.compare(type, typeValue.getType());
    if (i != 0) {
      return i;
    }
    return stringComparator.compare(value, typeValue.getValue());
  }
}
origin: gchq/Gaffer

@Override
public TypeValue deserialise(final byte[] bytes) throws SerialisationException {
  int lastDelimiter = 0;
  TypeValue typeValue = new TypeValue();
  for (int i = 0; i < bytes.length; i++) {
    if (bytes[i] == ByteArrayEscapeUtils.DELIMITER) {
      if (i > 0) {
        try {
          typeValue.setType(new String(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, i), CommonConstants.UTF_8));
        } catch (final UnsupportedEncodingException e) {
          throw new SerialisationException("Failed to deserialise the Type from TypeValue Object", e);
        }
      }
      lastDelimiter = i + 1;
      break;
    }
  }
  if (bytes.length > lastDelimiter) {
    try {
      typeValue.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 TypeValue Object", e);
    }
  }
  return typeValue;
}
origin: gchq/Gaffer

@Test
public void testCanSerialiseDeSerialiseCorrectly() throws SerialisationException {
  TypeValue typeValue = new TypeValue("testType", "testValue");
  byte[] bytes = serialiser.serialise(typeValue);
  String serialisedForm = new String(bytes);
  assertEquals("testType\0testValue", serialisedForm);
  TypeValue deSerialisedTypeValue = serialiser.deserialise(bytes);
  assertEquals(typeValue.getType(), deSerialisedTypeValue.getType());
  assertEquals(typeValue.getValue(), deSerialisedTypeValue.getValue());
  assertEquals(typeValue, deSerialisedTypeValue);
}
origin: gchq/Gaffer

  @Override
  public TypeValue apply(final Object value) {
    return new TypeValue(null, null != value ? value.toString() : null);
  }
}
origin: gchq/Gaffer

  @Test
  public void testHashCodeAndEqualsMethodTreatsEmptyStringAsNull() {
    // Given
    TypeValue typeValueEmptyStrings = new TypeValue("", "");
    TypeValue typeValueNullStrings = new TypeValue(null, null);

    // When
    boolean equalsResult = typeValueEmptyStrings.equals(typeValueNullStrings);

    // Then
    assertTrue(equalsResult);
    assertEquals(typeValueEmptyStrings.hashCode(), typeValueNullStrings.hashCode());
  }
}
origin: gchq/Gaffer

@Override
public byte[] serialise(final TypeValue typeValue) throws SerialisationException {
  String type = typeValue.getType();
  String value = typeValue.getValue();
  if ((null == type || type.isEmpty()) && (null == value || value.isEmpty())) {
    throw new SerialisationException("TypeValue passed to serialiser is blank");
  }
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  if (null != type) {
    try {
      out.write(ByteArrayEscapeUtils.escape(type.getBytes(CommonConstants.UTF_8)));
    } catch (final IOException e) {
      throw new SerialisationException("Failed to serialise the Type from TypeValue Object", e);
    }
  }
  out.write(ByteArrayEscapeUtils.DELIMITER);
  if (null != value) {
    try {
      out.write(ByteArrayEscapeUtils.escape(value.getBytes(CommonConstants.UTF_8)));
    } catch (final IOException e) {
      throw new SerialisationException("Failed to serialise the Value from TypeValue Object", e);
    }
  }
  return out.toByteArray();
}
origin: gchq/Gaffer

@Test
public void testCanSerialiseDeserialiseCorrectlyAndBeEscaped() throws SerialisationException {
  TypeValue typeValue = new TypeValue("testType", "testValue");
  byte[] bytes = ByteArrayEscapeUtils.escape(serialiser.serialise(typeValue));
  String serialisedForm = new String(bytes);
  assertEquals("testType\1\1testValue", serialisedForm);
  TypeValue deSerialisedTypeValue = serialiser.deserialise(ByteArrayEscapeUtils
      .unEscape(bytes));
  assertEquals(typeValue.getType(), deSerialisedTypeValue.getType());
  assertEquals(typeValue.getValue(), deSerialisedTypeValue.getValue());
  assertEquals(typeValue, deSerialisedTypeValue);
}
origin: uk.gov.gchq.gaffer/type

@Override
public TypeValue deserialise(final byte[] bytes) throws SerialisationException {
  int lastDelimiter = 0;
  TypeValue typeValue = new TypeValue();
  for (int i = 0; i < bytes.length; i++) {
    if (bytes[i] == ByteArrayEscapeUtils.DELIMITER) {
      if (i > 0) {
        try {
          typeValue.setType(new String(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, i), CommonConstants.UTF_8));
        } catch (final UnsupportedEncodingException e) {
          throw new SerialisationException("Failed to deserialise the Type from TypeValue Object", e);
        }
      }
      lastDelimiter = i + 1;
      break;
    }
  }
  if (bytes.length > lastDelimiter) {
    try {
      typeValue.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 TypeValue Object", e);
    }
  }
  return typeValue;
}
origin: gchq/Gaffer

  @Override
  public Pair<TypeValue, byte[]>[] getHistoricSerialisationPairs() {
    TypeValue typeValue = new TypeValue("testType", "testValue");
    return new Pair[]{
        new Pair(typeValue, new byte[]{116, 101, 115, 116, 84, 121, 112, 101, 0, 116, 101, 115, 116, 86, 97, 108, 117, 101})
    };

  }
}
origin: uk.gov.gchq.gaffer/parquet-store

@Override
public Object[] serialise(final TypeValue object) throws SerialisationException {
  if (null != object) {
    return new Object[]{object.getType(), object.getValue()};
  }
  return new Object[]{null, null};
}
origin: gchq/Gaffer

@Test
public void shouldConvertObjectToTypeValue() {
  // Given
  final ToTypeValue function = new ToTypeValue();
  final Object value = 1L;
  // When
  final TypeValue result = function.apply(value);
  // Then
  assertEquals(new TypeValue(null, value.toString()), result);
}
origin: uk.gov.gchq.gaffer/type

  @Override
  public int compareTo(final TypeValue typeValue) {
    if (null == typeValue) {
      return 1;
    }
    int i = stringComparator.compare(type, typeValue.getType());
    if (i != 0) {
      return i;
    }
    return stringComparator.compare(value, typeValue.getValue());
  }
}
origin: gchq/Gaffer

@Test
public void shouldConvertStringToTypeValue() {
  // Given
  final ToTypeValue function = new ToTypeValue();
  final Object value = "value1";
  // When
  final TypeValue result = function.apply(value);
  // Then
  assertEquals(new TypeValue(null, value.toString()), result);
}
origin: uk.gov.gchq.gaffer/spark-library

@Override
public void write(final Kryo kryo, final Output output, final TypeValue typeValue) {
  output.writeString(typeValue.getType());
  output.writeString(typeValue.getValue());
}
origin: gchq/Gaffer

@Test
public void shouldConvertNullToTypeValue() {
  // Given
  final ToTypeValue function = new ToTypeValue();
  final Object value = null;
  // When
  final TypeValue result = function.apply(value);
  // Then
  assertEquals(new TypeValue(null, null), result);
}
origin: uk.gov.gchq.gaffer/type

@Override
public byte[] serialise(final TypeValue typeValue) throws SerialisationException {
  String type = typeValue.getType();
  String value = typeValue.getValue();
  if ((null == type || type.isEmpty()) && (null == value || value.isEmpty())) {
    throw new SerialisationException("TypeValue passed to serialiser is blank");
  }
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  if (null != type) {
    try {
      out.write(ByteArrayEscapeUtils.escape(type.getBytes(CommonConstants.UTF_8)));
    } catch (final IOException e) {
      throw new SerialisationException("Failed to serialise the Type from TypeValue Object", e);
    }
  }
  out.write(ByteArrayEscapeUtils.DELIMITER);
  if (null != value) {
    try {
      out.write(ByteArrayEscapeUtils.escape(value.getBytes(CommonConstants.UTF_8)));
    } catch (final IOException e) {
      throw new SerialisationException("Failed to serialise the Value from TypeValue Object", e);
    }
  }
  return out.toByteArray();
}
origin: uk.gov.gchq.gaffer/parquet-store

@Override
public TypeValue deserialise(final Object[] objects) throws SerialisationException {
  if (objects.length == 2) {
    if (objects[0] instanceof String && objects[1] instanceof String) {
      return new TypeValue((String) objects[0], (String) objects[1]);
    } else if (null == objects[0]) {
      return null;
    }
  }
  throw new SerialisationException("Could not de-serialise objects to a TypeValue");
}
uk.gov.gchq.gaffer.typesTypeValue

Javadoc

A TypeValue is used to store information relating to types and associated values.

Most used methods

  • <init>
  • getType
  • getValue
  • setType
  • setValue
  • compareTo
  • equals
  • hashCode

Popular in Java

  • Finding current android device location
  • onCreateOptionsMenu (Activity)
  • compareTo (BigDecimal)
  • getResourceAsStream (ClassLoader)
  • NumberFormat (java.text)
    The abstract base class for all number formats. This class provides the interface for formatting and
  • PriorityQueue (java.util)
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natu
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • Get (org.apache.hadoop.hbase.client)
    Used to perform Get operations on a single row. To get everything for a row, instantiate a Get objec
  • Reflections (org.reflections)
    Reflections one-stop-shop objectReflections scans your classpath, indexes the metadata, allows you t
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now