/** * Returns the value at the given index. The given {@code index} is relative to * the {@link #accessor} indexing, <strong>not</strong> to this collection. * * @param index the index in the accessor (<em>not</em> the index in this collection). * @return the value at the given index. May be {@code null} or a collection. */ final Object valueAt(final int index) { return accessor.get(index, metadata); }
/** * Fetches the node value from the metadata object. */ @Override public Object getUserObject() { return accessor.get(indexInData, metadata); }
/** * Returns the value at the given index. The given {@code index} is relative to * the {@link #accessor} indexing, <strong>not</strong> to this collection. * * @param index the index in the accessor (<em>not</em> the index in this collection). * @return the value at the given index. May be {@code null} or a collection. */ final Object valueAt(final int index) { return accessor.get(index, metadata); }
/** * Fetches the node value from the metadata object. */ @Override public Object getUserObject() { return accessor.get(indexInData, metadata); }
/** * Returns the value for the specified metadata, or {@code null} if none. * If the given index is out of bounds, then this method returns {@code null}, * so it is safe to invoke this method even if {@link #indexOf(String, boolean)} * returned -1. * * @param index the index of the property for which to get a value. * @param metadata the metadata object to query. * @return the value, or {@code null} if none or if the given is out of bounds. * @throws BackingStoreException if the implementation threw a checked exception. */ Object get(final int index, final Object metadata) throws BackingStoreException { return (index >= 0 && index < allCount) ? get(getters[index], metadata) : null; }
/** * Returns the value for the specified metadata, or {@code null} if none. * If the given index is out of bounds, then this method returns {@code null}, * so it is safe to invoke this method even if {@link #indexOf(String, boolean)} * returned -1. * * @param index the index of the property for which to get a value. * @param metadata the metadata object to query. * @return the value, or {@code null} if none or if the given is out of bounds. * @throws BackingStoreException if the implementation threw a checked exception. */ Object get(final int index, final Object metadata) throws BackingStoreException { return (index >= 0 && index < allCount) ? get(getters[index], metadata) : null; }
/** * Returns the value corresponding to this entry. */ @Override public Object getValue() { final Object value = accessor.get(index, metadata); return valuePolicy.isSkipped(value) ? null : value; }
/** * Returns the value corresponding to this entry. */ @Override public Object getValue() { final Object value = accessor.get(index, metadata); return valuePolicy.isSkipped(value) ? null : value; }
/** * Returns a remark or warning to format with the value at the given index, or {@code null} if none. * This is used for notifying the user that a geographic box is spanning the anti-meridian. */ @Override CharSequence remarks(final int index, final Object metadata) { if (index == eastBoundLongitude) { Object east = super.get(index, metadata); if (east != null) { Object west = super.get(westBoundLongitude, metadata); if (west != null && (Double) east < (Double) west) { return Resources.formatInternational(Resources.Keys.BoxCrossesAntiMeridian); } } } return super.remarks(index, metadata); }
/** * Computes a hash code for the specified metadata. The hash code is defined as the sum * of hash code values of all non-empty properties, plus the hash code of the interface. * This is a similar contract than {@link java.util.Set#hashCode()} (except for the interface) * and ensures that the hash code value is insensitive to the ordering of properties. * * @throws BackingStoreException if the implementation threw a checked exception. */ public int hashCode(final Object metadata) throws BackingStoreException { assert type.isInstance(metadata) : metadata; int code = type.hashCode(); for (int i=0; i<standardCount; i++) { final Object value = get(getters[i], metadata); if (!isNullOrEmpty(value)) { code += value.hashCode(); } } return code; }
/** * Returns the value to which the specified key is mapped, or {@code null} * if this map contains no mapping for the key. */ @Override public Object get(final Object key) { if (key instanceof String) { final Object value = accessor.get(accessor.indexOf((String) key, false), metadata); if (!valuePolicy.isSkipped(value)) { return value; } } return null; }
/** * Returns the value to which the specified key is mapped, or {@code null} * if this map contains no mapping for the key. */ @Override public Object get(final Object key) { if (key instanceof String) { final Object value = accessor.get(accessor.indexOf((String) key, false), metadata); if (!valuePolicy.isSkipped(value)) { return value; } } return null; }
/** * Delegates to {@link PropertyAccessor#get(int, Object)}, then substitutes the value for the properties * handled in a special way. */ @Override Object get(final int index, final Object metadata) throws BackingStoreException { Object value = super.get(index, metadata); if (value != null) { if (index == westBoundLongitude || index == eastBoundLongitude) { value = new Longitude((Double) value); } else if (index == southBoundLatitude || index == northBoundLatitude) { value = new Latitude((Double) value); } } return value; }
/** * Delegates to {@link PropertyAccessor#get(int, Object)}, then substitutes the value for the properties * handled in a special way. */ @Override Object get(final int index, final Object metadata) throws BackingStoreException { Object value = super.get(index, metadata); if (value != null) { if (index == westBoundLongitude || index == eastBoundLongitude) { value = new Longitude((Double) value); } else if (index == southBoundLatitude || index == northBoundLatitude) { value = new Latitude((Double) value); } } return value; }
/** * Invokes {@link MetadataVisitor#visit(Class, Object)} for all non-null properties in the given metadata. * This method is not recursive, i.e. it does not traverse the children of the elements in the given metadata. * * @param visitor the object on which to invoke {@link MetadataVisitor#visit(Class, Object)}. * @param metadata the metadata instance for which to visit the non-null properties. * @throws Exception if an error occurred while visiting a property. */ final void walkReadable(final MetadataVisitor<?> visitor, final Object metadata) throws Exception { assert type.isInstance(metadata) : metadata; for (int i=0; i<standardCount; i++) { visitor.setCurrentProperty(names[i]); final Object value = get(getters[i], metadata); if (value != null) { final Object result = visitor.visit(elementTypes[i], value); if (result != value) { if (result == MetadataVisitor.SKIP_SIBLINGS) break; set(i, metadata, result, IGNORE_READ_ONLY); } } } }
/** * Moves {@link #next} to the first property with a valid value, * starting at the specified index. */ private void move(int index) { final int count = accessor.count(); while (index < count) { if (!valuePolicy.isSkipped(accessor.get(index, metadata))) { next = new Property(index); return; } index++; } next = null; }
/** * Returns a value of the "title" property of the given metadata object. * The title property is defined by {@link TitleProperty} annotation on the implementation class. * * @param metadata the metadata for which to get the title property, or {@code null}. * @return the title property value of the given metadata, or {@code null} if none. * * @see TitleProperty * @see ValueExistencePolicy#COMPACT */ final Object getTitle(final Object metadata) { if (metadata != null) { final Class<?> type = metadata.getClass(); final PropertyAccessor accessor = getAccessor(createCacheKey(type), false); if (accessor != null) { TitleProperty an = type.getAnnotation(TitleProperty.class); if (an != null || (an = accessor.implementation.getAnnotation(TitleProperty.class)) != null) { return accessor.get(accessor.indexOf(an.name(), false), metadata); } } } return null; }
/** * Moves {@link #next} to the first property with a valid value, * starting at the specified index. */ private void move(int index) { final int count = accessor.count(); while (index < count) { if (!valuePolicy.isSkipped(accessor.get(index, metadata))) { next = new Property(index); return; } index++; } next = null; }
/** * Invokes {@link SpecialCases#get(int, Object)} and ensures that the result is equals to the expected value. */ private void assertPropertyEquals(final String name, final Object expected) { assertEquals(name, expected, accessor.get(accessor.indexOf(name, true), box)); }
/** * Tests the {@link PropertyAccessor#set(int, Object, Object, int)} method * with a value that will need to be converted. The conversion will be from * {@link String} to {@link InternationalString}. The created metadata object is: * * {@preformat text * DefaultCitation * └─Title……………… Some title * } */ @Test @DependsOnMethod("testSet") public void testSetWithConversion() { final String expected = "Some title"; final DefaultCitation instance = new DefaultCitation(); final PropertyAccessor accessor = createPropertyAccessor(); final int index = accessor.indexOf("title", true); final Object oldValue = accessor.set(index, instance, expected, RETURN_PREVIOUS); final Object value = accessor.get(index, instance); assertNull ("title", oldValue); assertInstanceOf("title", InternationalString.class, value); assertSame ("title", expected, value.toString()); assertSame ("title", value, instance.getTitle()); }