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) {
public Set<Class<?>> getReferenceSchemaTypes() { Set<Class<?>> names = new HashSet<>(); for (AbstractSchemaProperty prop : get(SchemaPropertyRef.class)) { names.add(prop.getClassType()); } for (AbstractSchemaProperty prop : get(SchemaPropertyRefList.class)) { names.add(prop.getClassType()); } for (AbstractSchemaProperty prop : get(SchemaPropertyRefMap.class)) { names.add(prop.getClassType()); } return names; }
@Override public int hashCode() { return super.getHashCode() + Objects.hashCode(collectionType, schemaName); }
private Object getValuesAsObject(final AbstractSchemaProperty property, final Bean bean) { String propertyName = property.getName(); Object value = null; if (property instanceof SchemaProperty) {
public String getReferenceSchemaName(String propertyName) { for (AbstractSchemaProperty schema : properties.values()) { if (!schema.getFieldName().equals(propertyName)) { continue; } if (schema instanceof SchemaPropertyRef) { return ((SchemaPropertyRef) schema).getSchemaName(); } if (schema instanceof SchemaPropertyRefList) { return ((SchemaPropertyRefList) schema).getSchemaName(); } if (schema instanceof SchemaPropertyRefMap) { return ((SchemaPropertyRefMap) schema).getSchemaName(); } } return null; }
/** * 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; }
/** * 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()); }
@Override public int hashCode() { return super.getHashCode() + Objects.hashCode(getSchemaName()); }
public String toString() { return super.toStringHelper(SchemaProperty.class).add("type", getType()) .add("defaultValue", getDefaultValue()).toString(); }
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); } }
@Override public final String toString() { return super.toStringHelper(SchemaPropertyRef.class).add("schema-name", schemaName) .toString(); } }
/** * 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; }
@Override public int hashCode() { return Objects.hashCode(super.getHashCode(), getDefaultValue(), getType()); }
boolean equals(AbstractSchemaProperty o) { return equal(getName(), o.getName()) && equal(getFieldName(), o.getFieldName()) && equal(getDesc(), o.getDesc()) && equal(isImmutable(), o.isImmutable()); } }
@Override public int hashCode() { return super.getHashCode() + Objects.hashCode(mapType, schemaName); }
@Override public int hashCode() { return Objects.hashCode(super.getHashCode(), getType(), getCollectionType()); }
/** * Returns all properties that have been marked as indexed. * * @param <T> type * @return a list of properties. */ public <T extends AbstractSchemaProperty> Set<T> getIndexed() { HashSet<AbstractSchemaProperty> indexed = new HashSet<>(); for (AbstractSchemaProperty prop : properties.values()) { if (prop.isIndexed()) indexed.add(prop); } return (Set<T>) indexed; }
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); } } }