/** * Returns all property names that exist for this schema. */ public Set<String> getPropertyNames() { Set<String> names = new HashSet<>(); for (AbstractSchemaProperty prop : get(SchemaProperty.class)) { names.add(prop.getName()); } for (AbstractSchemaProperty prop : get(SchemaPropertyList.class)) { names.add(prop.getName()); } return names; }
public ConfigIndex(Schema schema) { for(AbstractSchemaProperty property : schema.getIndexed()) { String propertyName = property.getName(); Class<?> type = getType(property); if(Number.class.isAssignableFrom(type)) { NumberAttribute attr = new NumberAttribute(propertyName); attributes.put(propertyName, attr); } else if (Collection.class.isAssignableFrom(type)) { MultiObjectAttribute attr = new MultiObjectAttribute(propertyName); attributes.put(propertyName, attr); } else if (Map.class.isAssignableFrom(type)) { MultiObjectAttribute attr = new MultiObjectAttribute(propertyName); attributes.put(propertyName, attr); } else { ObjectAttribute attr = new ObjectAttribute(propertyName); attributes.put(propertyName, attr); } } } private Class<?> getType(final AbstractSchemaProperty property) {
/** * Returns all reference names that exist for this schema. */ public Set<String> getReferenceNames() { Set<String> names = new HashSet<>(); for (AbstractSchemaProperty prop : get(SchemaPropertyRef.class)) { names.add(prop.getName()); } for (AbstractSchemaProperty prop : get(SchemaPropertyRefList.class)) { names.add(prop.getName()); } for (AbstractSchemaProperty prop : get(SchemaPropertyRefMap.class)) { names.add(prop.getName()); } return names; }
private Object getValuesAsObject(final AbstractSchemaProperty property, final Bean bean) { String propertyName = property.getName(); Object value = null; if (property instanceof SchemaProperty) {
/** * Returns a specific properties of a particular type identified with a name. * * @param clazz specific type of property to get. * @param name The AbstractSchemaProperty name of the property. * @return Matching property. */ public <T extends AbstractSchemaProperty> T get(final Class<T> clazz, final String name) { Set<T> propertyCollection = get(clazz); for (T property : propertyCollection) { if (property.getName().equals(name)) { return property; } } return null; }
private static String validateSingle(Bean bean, AbstractSchemaProperty prop) { List<String> values = bean.getValues(prop.getName()); if (values == null) { return null; } if (prop.isImmutable()) { throw Events.CFG306_PROPERTY_IMMUTABLE(bean.getId(), prop.getName()); } if (values.size() > 1) { throw Events.CFG106_WRONG_MULTIPLICITY_TYPE(bean.getId(), prop.getName()); } if (values.size() == 0) { return null; } return values.get(0); }
int getHashCode() { return Objects.hashCode(getName(), getFieldName(), getDesc(), isImmutable()); }
private static String validateSingle(Bean bean, AbstractSchemaProperty prop) { List<String> values = bean.getValues(prop.getName()); if (values == null) { return null; } if (prop.isImmutable()) { throw Events.CFG306_PROPERTY_IMMUTABLE(bean.getId(), prop.getName()); } if (values.size() > 1) { throw Events.CFG106_WRONG_MULTIPLICITY_TYPE(bean.getId(), prop.getName()); } return values.get(0); } }
public ConfigIndexFields(Bean bean) { Preconditions.checkNotNull(bean.getSchema(), "Schema must be available on bean."); this.id = bean.getId(); for (AbstractSchemaProperty prop : bean.getSchema().getIndexed()) { Object value = getValuesAsObject(prop, bean); if (value != null) { fields.put(prop.getName(), value); } } }