/** * Create a new attribute pair. * @param name The attribute name. * @param val The value. */ private Attribute(@Nonnull TypedName<T> name, @Nonnull T val) { Preconditions.checkNotNull(name, "name"); Preconditions.checkNotNull(val, "value"); Preconditions.checkArgument(name.getRawType().isInstance(val), "creating attribute %s: value '%s' is not of correct type", name, val); this.name = name; value = val; }
@SuppressWarnings("unchecked") @Nullable @Override public <T> T maybeGet(TypedName<T> name) { return name == CommonAttributes.ENTITY_ID ? (T) name.getRawType().cast(getId()) : null; }
@SuppressWarnings("unchecked") @Nullable @Override public <T> T maybeGet(TypedName<T> name) { int idx = attributeNames.lookup(name); if (idx < 0) { return null; } else if (idx == 0) { return (T) name.getRawType().cast(getId()); } else { return (T) name.getRawType().cast(attributeValues[idx-1]); } }
@Override public String toString() { String tname; if (ClassUtils.isPrimitiveWrapper(getRawType())) { tname = ClassUtils.wrapperToPrimitive(getRawType()).getName(); } else { tname = type.toString(); } return "TypedName[" + name + ": " + tname + "]"; }
@Nullable @Override public <T> T maybeGet(TypedName<T> name) { int ap = attributes.lookup(name); return ap >= 0 ? (T) name.getRawType().cast(attrStores[ap].get(position)) : null; }
/** * {@inheritDoc} * * This implementation delegates to {@link #hasAttribute(String)} */ @Override public boolean hasAttribute(TypedName<?> name) { Object value = maybeGet(name.getName()); return value != null && name.getRawType().isInstance(value); }
/** * {@inheritDoc} * * This implementation delegates to {@link #maybeGet(String)} and checks the type. */ @Nullable @Override public <T> T maybeGet(TypedName<T> name) { try { // FIXME This is not fully type-safe! return (T) name.getRawType().cast(maybeGet(name.getName())); } catch (ClassCastException e) { throw new IllegalArgumentException(e); } }
@Override public <T> EntityBuilder setAttribute(TypedName<T> name, T val) { Preconditions.checkNotNull(name, "attribute"); Preconditions.checkNotNull(val, "value"); Preconditions.checkArgument(name.getRawType().isInstance(val), "value %s not of type %s", val, name.getType()); if (name == CommonAttributes.ENTITY_ID) { return setId(((Long) val).longValue()); } else { attributes.put(name.getName(), Attribute.create(name, val)); return this; } }
/** * Create an entity index builder for an attribute. * @param name The attribute. * @return The index builder. */ @SuppressWarnings("unchecked") public static EntityIndexBuilder create(TypedName<?> name) { if (name.getRawType().equals(Long.class)) { return new LongEntityIndexBuilder((TypedName<Long>) name); } else { return new GenericEntityIndexBuilder(name); } } }
/** * Parse a string containing this attribute's value. * @return The attribute value. */ public T parseString(String value) { FromStringConverter cvt = converter; if (cvt == null) { converter = cvt = TypeUtils.lookupFromStringConverter(type); } return (T) cvt.convertFromString(getRawType(), value); }
PackedEntityCollection(EntityType et, AttributeSet attrs, AttrStore[] stores, PackIndex[] idxes, Class<? extends EntityBuilder> ebc) { entityType = et; attributes = attrs; attrStores = stores; indexes = idxes; idStore = (LongAttrStore) stores[0]; size = idStore.size(); storeSetters = new AttrSetter[stores.length]; for (int i = 0; i < stores.length; i++) { AttrStore as = stores[i]; TypedName<?> an = attributes.getAttribute(i); if (as instanceof LongAttrStore && an.getRawType().equals(Long.class)) { storeSetters[i] = new LongAttrSetter((TypedName) an, (LongAttrStore) as); } else if (as instanceof DoubleAttrStore && an.getRawType().equals(Double.class)) { storeSetters[i] = new DoubleAttrSetter((TypedName) an, (DoubleAttrStore) as); } else { storeSetters[i] = new ObjectAttrSetter(an, as); } } if (ebc == null || ebc.equals(BasicEntityBuilder.class)) { entityBuilder = IndirectEntity::new; } else { entityBuilder = new Reconstitutor(ebc); } }
cn.version = V1_8; Class<? extends AttrMethod> sc; if (attr.getRawType().equals(Long.class) && smVtype.equals(long.class)) { sc = LongAttrMethod.class; } else if (attr.getRawType().equals(Double.class) && smVtype.equals(double.class)) { sc = DoubleAttrMethod.class; } else { if (attr.getRawType().equals(Long.class) && smVtype.equals(long.class)) { cn.methods.add(generateLongSetter(type, smethod)); if (attr.getRawType().equals(Double.class) && smVtype.equals(double.class)) { cn.methods.add(generateDoubleSetter(type, smethod));
private PackIndex buildIndex(int aidx) { TypedName<?> tn = attributes.getAttribute(aidx); logger.debug("indexing column {} of {}", tn, entityType); PackIndex.Builder builder; if (tn.getRawType().equals(Long.class)) { builder = new PackIndex.LongBuilder(); } else { builder = new PackIndex.GenericBuilder(); } for (int i = 0; i < size; i++) { builder.add(storeBuilders[aidx].get(i), i); } return builder.build(); }
@SuppressWarnings("unchecked") @Nullable @Override public <T> T maybeGet(TypedName<T> name) { int idx = attributeNames.lookup(name); if (idx < 0) { return null; } else if (idx == 0) { return (T) name.getRawType().cast(getId()); } else { return (T) name.getRawType().cast(attributeValues[idx-1]); } }
@SuppressWarnings("unchecked") @Nullable @Override public <T> T maybeGet(TypedName<T> name) { return name == CommonAttributes.ENTITY_ID ? (T) name.getRawType().cast(getId()) : null; }
@Override public String toString() { String tname; if (ClassUtils.isPrimitiveWrapper(getRawType())) { tname = ClassUtils.wrapperToPrimitive(getRawType()).getName(); } else { tname = type.toString(); } return "TypedName[" + name + ": " + tname + "]"; }
@Nullable @Override public <T> T maybeGet(TypedName<T> name) { int ap = attributes.lookup(name); return ap >= 0 ? (T) name.getRawType().cast(attrStores[ap].get(position)) : null; }
/** * {@inheritDoc} * * This implementation delegates to {@link #hasAttribute(String)} */ @Override public boolean hasAttribute(TypedName<?> name) { Object value = maybeGet(name.getName()); return value != null && name.getRawType().isInstance(value); }
@Override public <T> EntityBuilder setAttribute(TypedName<T> name, T val) { Preconditions.checkNotNull(name, "attribute"); Preconditions.checkNotNull(val, "value"); Preconditions.checkArgument(name.getRawType().isInstance(val), "value %s not of type %s", val, name.getType()); if (name == CommonAttributes.ENTITY_ID) { return setId(((Long) val).longValue()); } else { attributes.put(name.getName(), Attribute.create(name, val)); return this; } }
/** * Parse a string containing this attribute's value. * @return The attribute value. */ public T parseString(String value) { FromStringConverter cvt = converter; if (cvt == null) { converter = cvt = TypeUtils.lookupFromStringConverter(type); } return (T) cvt.convertFromString(getRawType(), value); }