@Override
 public Set<Object> getValues(Object value) {
   Set<Object> result = new HashSet<Object>();
   for (Object element : ((List<Object>) value)) {
     result.addAll(valueType.getValues(element));
   }
   return result;
 }
 @Override
 public void write(Object value, DataOutput dataOutput, IdentityRecordStack parentRecords)
     throws RepositoryException, InterruptedException {
   List<Object> values = ((List<Object>) value);
   dataOutput.writeInt(values.size());
   for (Object element : values) {
     valueType.write(element, dataOutput, parentRecords);
   }
 }
 @Override
 @SuppressWarnings("unchecked")
 public List<Object> read(DataInput dataInput) throws RepositoryException, InterruptedException {
   int nrOfValues = dataInput.readInt();
   List<Object> result = new ArrayList<Object>(nrOfValues);
   for (int i = 0; i < nrOfValues; i++) {
     result.add(valueType.read(dataInput));
   }
   return result;
 }
Beispiel #4
0
 @Override
 protected String formatPrimitiveValue(Object value, ValueType valueType) {
   String type = valueType.getPrimitive().getName();
   if (type.equals("DATE")) {
     LocalDate date = (LocalDate) value;
     return String.valueOf(date.getYear());
   } else if (type.equals("DATETIME")) {
     DateTime dateTime = (DateTime) value;
     return String.valueOf(dateTime.getYear());
   } else {
     throw new RuntimeException("Unexpected type: " + type);
   }
 }
  @Test
  public void testFromString() throws Exception {
    IdGenerator idGenerator = new IdGeneratorImpl();

    ValueType valueType = mock(ValueType.class);

    when(valueType.getBaseName()).thenReturn("STRING");
    assertEquals("foo", FieldValueStringConverter.fromString("foo", valueType, idGenerator));

    when(valueType.getBaseName()).thenReturn("INTEGER");
    assertEquals(
        new Integer(123), FieldValueStringConverter.fromString("123", valueType, idGenerator));

    when(valueType.getBaseName()).thenReturn("LONG");
    assertEquals(
        new Long(12345), FieldValueStringConverter.fromString("12345", valueType, idGenerator));

    when(valueType.getBaseName()).thenReturn("DOUBLE");
    assertEquals(
        new Double(12345.6),
        FieldValueStringConverter.fromString("12345.6", valueType, idGenerator));

    when(valueType.getBaseName()).thenReturn("DECIMAL");
    assertEquals(
        new BigDecimal("12345.12345"),
        FieldValueStringConverter.fromString("12345.12345", valueType, idGenerator));

    when(valueType.getBaseName()).thenReturn("URI");
    assertEquals(
        new URI("http://www.ngdata.com/"),
        FieldValueStringConverter.fromString("http://www.ngdata.com/", valueType, idGenerator));

    when(valueType.getBaseName()).thenReturn("BOOLEAN");
    assertEquals(
        Boolean.TRUE, FieldValueStringConverter.fromString("true", valueType, idGenerator));
    assertEquals(
        Boolean.FALSE, FieldValueStringConverter.fromString("false", valueType, idGenerator));

    when(valueType.getBaseName()).thenReturn("LINK");
    assertEquals(
        new Link(idGenerator.newRecordId("foobar")),
        FieldValueStringConverter.fromString("USER.foobar", valueType, idGenerator));

    when(valueType.getBaseName()).thenReturn("DATE");
    assertEquals(
        new LocalDate(2012, 6, 28),
        FieldValueStringConverter.fromString("2012-06-28", valueType, idGenerator));

    when(valueType.getBaseName()).thenReturn("DATETIME");
    assertEquals(
        new DateTime(2012, 6, 28, 5, 36, 0, 0, DateTimeZone.UTC),
        FieldValueStringConverter.fromString("2012-06-28T05:36Z", valueType, idGenerator));
  }
 @Override
 public int getNestingLevel() {
   return 1 + valueType.getNestingLevel();
 }
 @Override
 public ValueType getDeepestValueType() {
   return valueType.getDeepestValueType();
 }
 @Override
 public boolean isHierarchical() {
   return valueType.isHierarchical();
 }