@Override @Nonnull public <T> List<Entity> find(Attribute<T> attr) { return find(attr.getTypedName(), attr.getValue()); }
@Nonnull @Override public <T> List<Entity> find(Attribute<T> attr) { return find(attr.getTypedName(), attr.getValue()); }
@Override public String toString() { ToStringBuilder tsb = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); tsb.append("type", getType()); for (Attribute<?> av: getAttributes()) { tsb.append(av.getTypedName().toString(), av.getValue()); } return tsb.toString(); }
/** * Set an attribute in the entity. * @param attr The attribute to set. * @param <T> The attribute type. * @return The entity builder (for chaining). * @throws NoSuchAttributeException if the specified attribute is not supported by this entity. */ public <T> EntityBuilder setAttribute(Attribute<T> attr) { setAttribute(attr.getTypedName(), attr.getValue()); return this; }
@Override public Entity build() { Preconditions.checkState(type != null, "Entity type not set"); Preconditions.checkState(idSet, "ID not set"); if (attributes.isEmpty() || attributes.keySet().equals(Collections.singleton(CommonAttributes.ENTITY_ID))) { return new BareEntity(type, id); } else { List<TypedName<?>> names = new ArrayList<>(attributes.size()); names.add(CommonAttributes.ENTITY_ID); for (Attribute<?> a: attributes.values()) { names.add(a.getTypedName()); } assert names.lastIndexOf(CommonAttributes.ENTITY_ID) == 0; AttributeSet aset = AttributeSet.create(names); Object[] values = new Object[aset.size()]; for (Attribute<?> a: attributes.values()) { int i = aset.lookup(a.getTypedName()); values[i-1] = a.getValue(); } return new BasicEntity(type, id, aset, values); } } }
/** * Determine whether this query matches the specified entity. * @param entity The entity to test. * @return The entity. */ public boolean matches(Entity entity) { if (!entity.getType().equals(entityType)) { return false; } for (Attribute<?> attr: filterFields) { Object val = entity.maybeGet(attr.getTypedName()); if (!attr.getValue().equals(val)) { return false; } } return true; } }
@Override public void describeTo(DescriptionWriter writer) { writer.putField("type", getType()); for (Attribute<?> av: getAttributes()) { writer.putField(av.getTypedName().toString(), av.getValue()); } }
int ap = attributes.lookup(a.getTypedName()); if (ap >= 0) { storeBuilders[ap].add(a.getValue());
@Override @Nonnull public <T> List<Entity> find(Attribute<T> attr) { return find(attr.getTypedName(), attr.getValue()); }
@Nonnull @Override public <T> List<Entity> find(Attribute<T> attr) { return find(attr.getTypedName(), attr.getValue()); }
@Override public String toString() { ToStringBuilder tsb = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); tsb.append("type", getType()); for (Attribute<?> av: getAttributes()) { tsb.append(av.getTypedName().toString(), av.getValue()); } return tsb.toString(); }
/** * Set an attribute in the entity. * @param attr The attribute to set. * @param <T> The attribute type. * @return The entity builder (for chaining). * @throws NoSuchAttributeException if the specified attribute is not supported by this entity. */ public <T> EntityBuilder setAttribute(Attribute<T> attr) { setAttribute(attr.getTypedName(), attr.getValue()); return this; }
@Override public Entity build() { Preconditions.checkState(type != null, "Entity type not set"); Preconditions.checkState(idSet, "ID not set"); if (attributes.isEmpty() || attributes.keySet().equals(Collections.singleton(CommonAttributes.ENTITY_ID))) { return new BareEntity(type, id); } else { List<TypedName<?>> names = new ArrayList<>(attributes.size()); names.add(CommonAttributes.ENTITY_ID); for (Attribute<?> a: attributes.values()) { names.add(a.getTypedName()); } assert names.lastIndexOf(CommonAttributes.ENTITY_ID) == 0; AttributeSet aset = AttributeSet.create(names); Object[] values = new Object[aset.size()]; for (Attribute<?> a: attributes.values()) { int i = aset.lookup(a.getTypedName()); values[i-1] = a.getValue(); } return new BasicEntity(type, id, aset, values); } } }
/** * Determine whether this query matches the specified entity. * @param entity The entity to test. * @return The entity. */ public boolean matches(Entity entity) { if (!entity.getType().equals(entityType)) { return false; } for (Attribute<?> attr: filterFields) { Object val = entity.maybeGet(attr.getTypedName()); if (!attr.getValue().equals(val)) { return false; } } return true; } }
@Override public void describeTo(DescriptionWriter writer) { writer.putField("type", getType()); for (Attribute<?> av: getAttributes()) { writer.putField(av.getTypedName().toString(), av.getValue()); } }
int ap = attributes.lookup(a.getTypedName()); if (ap >= 0) { storeBuilders[ap].add(a.getValue());