@Test public void convertTypeIfNeededNonStringCollectionToStringCollection() { Object propertyValueCollection = PropertySpecifier.convertTypeIfNeeded( ImmutableList.of(new Configuration("cname", ConfigurationFormat.CISCO_IOS)), Schema.list(Schema.STRING)); assertThat(propertyValueCollection, equalTo(ImmutableList.of("cname"))); }
public static Object convertTypeIfNeeded(Object propertyValue, Schema targetSchema) { Object outputPropertyValue = propertyValue; if (outputPropertyValue instanceof Map<?, ?>) { outputPropertyValue = ((Map<?, ?>) outputPropertyValue) .keySet().stream().map(Object::toString).collect(ImmutableSet.toImmutableSet()); } if (targetSchema.equals(Schema.STRING) && outputPropertyValue != null && !(outputPropertyValue instanceof String)) { if (outputPropertyValue instanceof ComparableStructure) { outputPropertyValue = ((ComparableStructure<?>) outputPropertyValue).getName(); } else { outputPropertyValue = outputPropertyValue.toString(); } } else if ((targetSchema.equals(Schema.list(Schema.STRING)) || targetSchema.equals(Schema.set(Schema.STRING))) && outputPropertyValue instanceof Collection<?>) { Collection<?> outputCollection = (Collection<?>) outputPropertyValue; if (!outputCollection.isEmpty() && !(outputCollection.iterator().next() instanceof String)) { Stream<?> stream = outputCollection.stream() .map( e -> (e instanceof ComparableStructure) ? ((ComparableStructure<?>) e).getName() : e.toString()); outputPropertyValue = targetSchema.getType() == Type.LIST ? stream.collect(ImmutableList.toImmutableList()) : stream.collect(ImmutableSet.toImmutableSet()); } } return outputPropertyValue; }
PropertySpecifier { public static Object convertTypeIfNeeded(Object propertyValue, Schema targetSchema) { Object outputPropertyValue = propertyValue; if (outputPropertyValue instanceof Map<?, ?>) { outputPropertyValue = ((Map<?, ?>) outputPropertyValue) .keySet().stream().map(Object::toString).collect(ImmutableSet.toImmutableSet()); } if (targetSchema.equals(Schema.STRING) && outputPropertyValue != null && !(outputPropertyValue instanceof String)) { if (outputPropertyValue instanceof ComparableStructure) { outputPropertyValue = ((ComparableStructure<?>) outputPropertyValue).getName(); } else { outputPropertyValue = outputPropertyValue.toString(); } } else if ((targetSchema.equals(Schema.list(Schema.STRING)) || targetSchema.equals(Schema.set(Schema.STRING))) && outputPropertyValue instanceof Collection<?>) { Collection<?> outputCollection = (Collection<?>) outputPropertyValue; if (!outputCollection.isEmpty() && !(outputCollection.iterator().next() instanceof String)) { Stream<?> stream = outputCollection.stream() .map( e -> (e instanceof ComparableStructure) ? ((ComparableStructure<?>) e).getName() : e.toString()); outputPropertyValue = targetSchema.getType() == Type.LIST ? stream.collect(ImmutableList.toImmutableList()) : stream.collect(ImmutableSet.toImmutableSet()); } } return outputPropertyValue; } }
PropertySpecifier { public static Object convertTypeIfNeeded(Object propertyValue, Schema targetSchema) { Object outputPropertyValue = propertyValue; if (outputPropertyValue instanceof Map<?, ?>) { outputPropertyValue = ((Map<?, ?>) outputPropertyValue) .keySet().stream().map(Object::toString).collect(ImmutableSet.toImmutableSet()); } if (targetSchema.equals(Schema.STRING) && outputPropertyValue != null && !(outputPropertyValue instanceof String)) { if (outputPropertyValue instanceof ComparableStructure) { outputPropertyValue = ((ComparableStructure<?>) outputPropertyValue).getName(); } else { outputPropertyValue = outputPropertyValue.toString(); } } else if ((targetSchema.equals(Schema.list(Schema.STRING)) || targetSchema.equals(Schema.set(Schema.STRING))) && outputPropertyValue instanceof Collection<?>) { Collection<?> outputCollection = (Collection<?>) outputPropertyValue; if (!outputCollection.isEmpty() && !(outputCollection.iterator().next() instanceof String)) { Stream<?> stream = outputCollection.stream() .map( e -> (e instanceof ComparableStructure) ? ((ComparableStructure<?>) e).getName() : e.toString()); outputPropertyValue = targetSchema.getType() == Type.LIST ? stream.collect(ImmutableList.toImmutableList()) : stream.collect(ImmutableSet.toImmutableSet()); } } return outputPropertyValue; }  }
PropertySpecifier { public static Object convertTypeIfNeeded(Object propertyValue, Schema targetSchema) { Object outputPropertyValue = propertyValue; if (outputPropertyValue instanceof Map<?, ?>) { outputPropertyValue = ((Map<?, ?>) outputPropertyValue) .keySet().stream().map(Object::toString).collect(ImmutableSet.toImmutableSet()); } if (targetSchema.equals(Schema.STRING) && outputPropertyValue != null && !(outputPropertyValue instanceof String)) { if (outputPropertyValue instanceof ComparableStructure) { outputPropertyValue = ((ComparableStructure<?>) outputPropertyValue).getName(); } else { outputPropertyValue = outputPropertyValue.toString(); } } else if ((targetSchema.equals(Schema.list(Schema.STRING)) || targetSchema.equals(Schema.set(Schema.STRING))) && outputPropertyValue instanceof Collection<?>) { Collection<?> outputCollection = (Collection<?>) outputPropertyValue; if (!outputCollection.isEmpty() && !(outputCollection.iterator().next() instanceof String)) { Stream<?> stream = outputCollection.stream() .map( e -> (e instanceof ComparableStructure) ? ((ComparableStructure<?>) e).getName() : e.toString()); outputPropertyValue = targetSchema.getType() == Type.LIST ? stream.collect(ImmutableList.toImmutableList()) : stream.collect(ImmutableSet.toImmutableSet()); } } return outputPropertyValue; }  static Object convertTypeIfNeeded(Object propertyValue, Schema targetSchema); static void fillProperty(
      PropertyDescriptor<T> propertyDescriptor, T object, String columnName, RowBuilder row); abstract List<String> getMatchingProperties(); }
PropertySpecifier { public static Object convertTypeIfNeeded(Object propertyValue, Schema targetSchema) { Object outputPropertyValue = propertyValue; if (outputPropertyValue instanceof Map<?, ?>) { outputPropertyValue = ((Map<?, ?>) outputPropertyValue) .keySet().stream().map(Object::toString).collect(ImmutableSet.toImmutableSet()); } if (targetSchema.equals(Schema.STRING) && outputPropertyValue != null && !(outputPropertyValue instanceof String)) { if (outputPropertyValue instanceof ComparableStructure) { outputPropertyValue = ((ComparableStructure<?>) outputPropertyValue).getName(); } else { outputPropertyValue = outputPropertyValue.toString(); } } else if ((targetSchema.equals(Schema.list(Schema.STRING)) || targetSchema.equals(Schema.set(Schema.STRING))) && outputPropertyValue instanceof Collection<?>) { Collection<?> outputCollection = (Collection<?>) outputPropertyValue; if (!outputCollection.isEmpty() && !(outputCollection.iterator().next() instanceof String)) { Stream<?> stream = outputCollection.stream() .map( e -> (e instanceof ComparableStructure) ? ((ComparableStructure<?>) e).getName() : e.toString()); outputPropertyValue = targetSchema.getType() == Type.LIST ? stream.collect(ImmutableList.toImmutableList()) : stream.collect(ImmutableSet.toImmutableSet()); } } return outputPropertyValue; }  static Object convertTypeIfNeeded(Object propertyValue, Schema targetSchema); static void fillProperty(
      PropertyDescriptor<T> propertyDescriptor, T object, String columnName, RowBuilder row); abstract List<String> getMatchingProperties();  }