/** * Set an extra attribute. An extra attribute is an attribute that is not provided by a bean-style setter. * * The default implementation throws {@link NoSuchAttributeException}. * * @param name The attribute name to clear. * @param val The attribute value to set. */ public <T> void setExtraAttribute(TypedName<T> name, T val) { throw new NoSuchAttributeException(name.toString()); }
/** * {@inheritDoc} * * This implementation delegates to {@link #maybeGet(TypedName)}. */ @Nonnull @Override public <T> T get(TypedName<T> name) { T val = maybeGet(name); if (val == null) { throw new NoSuchAttributeException(name.toString()); } else { return val; } }
@Override public long getLong(TypedName<Long> name) { int ap = attributes.lookup(name); if (ap < 0) { throw new NoSuchAttributeException(name.toString()); } AttrStore as = attrStores[ap]; if (as.isNull(position)) { throw new NoSuchElementException(name.toString()); } assert as instanceof LongAttrStore; return ((LongAttrStore) as).getLong(position); } }
@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(); }
@Override public double getDouble(TypedName<Double> name) { int idx = layout.attributes.lookup(name); if (idx >= 0) { BeanAttributeGetter gf = layout.getters.get(idx); return gf.getDouble(this); } else { throw new NoSuchAttributeException(name.toString()); } }
@Override public int getInteger(TypedName<Integer> name) { int idx = layout.attributes.lookup(name); if (idx >= 0) { BeanAttributeGetter gf = layout.getters.get(idx); return gf.getInt(this); } else { throw new NoSuchAttributeException(name.toString()); } }
@Override public boolean getBoolean(TypedName<Boolean> name) { int idx = layout.attributes.lookup(name); if (idx >= 0) { BeanAttributeGetter gf = layout.getters.get(idx); return gf.getBoolean(this); } else { throw new NoSuchAttributeException(name.toString()); } }
@Override public long getLong(TypedName<Long> name) { int idx = layout.attributes.lookup(name); if (idx >= 0) { BeanAttributeGetter gf = layout.getters.get(idx); return gf.getLong(this); } else { throw new NoSuchAttributeException(name.toString()); } }
@Override public void describeTo(DescriptionWriter writer) { writer.putField("type", getType()); for (Attribute<?> av: getAttributes()) { writer.putField(av.getTypedName().toString(), av.getValue()); } }
@Test public void testBasicField() { TypedName<String> attribute = TypedName.create("foo", String.class); assertThat(attribute.getName(), equalTo("foo")); assertThat(attribute.getType(), equalTo(TypeToken.of(String.class))); // check equality to random other object assertThat(attribute, not(equalTo((Object) "foo"))); assertThat(TypedName.create("foo", String.class), sameInstance(attribute)); assertThat(attribute.toString(), notNullValue()); assertThat(attribute.toString(), matchesPattern("^TypedName\\[foo: .*\\]$")); }
/** * Set an extra attribute. An extra attribute is an attribute that is not provided by a bean-style setter. * * The default implementation throws {@link NoSuchAttributeException}. * * @param name The attribute name to clear. * @param val The attribute value to set. */ public <T> void setExtraAttribute(TypedName<T> name, T val) { throw new NoSuchAttributeException(name.toString()); }
@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(); }
/** * {@inheritDoc} * * This implementation delegates to {@link #maybeGet(TypedName)}. */ @Nonnull @Override public <T> T get(TypedName<T> name) { T val = maybeGet(name); if (val == null) { throw new NoSuchAttributeException(name.toString()); } else { return val; } }
@Override public long getLong(TypedName<Long> name) { int ap = attributes.lookup(name); if (ap < 0) { throw new NoSuchAttributeException(name.toString()); } AttrStore as = attrStores[ap]; if (as.isNull(position)) { throw new NoSuchElementException(name.toString()); } assert as instanceof LongAttrStore; return ((LongAttrStore) as).getLong(position); } }
@Override public int getInteger(TypedName<Integer> name) { int idx = layout.attributes.lookup(name); if (idx >= 0) { BeanAttributeGetter gf = layout.getters.get(idx); return gf.getInt(this); } else { throw new NoSuchAttributeException(name.toString()); } }
@Override public boolean getBoolean(TypedName<Boolean> name) { int idx = layout.attributes.lookup(name); if (idx >= 0) { BeanAttributeGetter gf = layout.getters.get(idx); return gf.getBoolean(this); } else { throw new NoSuchAttributeException(name.toString()); } }
@Override public long getLong(TypedName<Long> name) { int idx = layout.attributes.lookup(name); if (idx >= 0) { BeanAttributeGetter gf = layout.getters.get(idx); return gf.getLong(this); } else { throw new NoSuchAttributeException(name.toString()); } }
@Override public double getDouble(TypedName<Double> name) { int idx = layout.attributes.lookup(name); if (idx >= 0) { BeanAttributeGetter gf = layout.getters.get(idx); return gf.getDouble(this); } else { throw new NoSuchAttributeException(name.toString()); } }
@Override public void describeTo(DescriptionWriter writer) { writer.putField("type", getType()); for (Attribute<?> av: getAttributes()) { writer.putField(av.getTypedName().toString(), av.getValue()); } }