/** * 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); }
/** * Associates the specified value with the specified key in this map. * * @throws IllegalArgumentException if the given key is not the name of a property in the metadata. * @throws ClassCastException if the given value is not of the expected type. * @throws UnmodifiableMetadataException if the property for the given key is read-only. */ @Override public Object put(final String key, final Object value) { final Object old = accessor.set(accessor.indexOf(key, true), metadata, value, RETURN_PREVIOUS); return valuePolicy.isSkipped(old) ? null : old; }
/** * Returns the information to which the specified key is mapped, * or {@code null} if this map contains no mapping for the key. */ @Override public ExtendedElementInformation get(final Object key) { if (key instanceof String) { return accessor.information(accessor.indexOf((String) key, false)); } return null; }
final int count = accessor.count(); for (int i=0; i<count; i++) { testingMethod = accessor.name(i, KeyNamePolicy.METHOD_NAME); if (skipTest(accessor.implementation, testingMethod)) { continue; final String property = accessor.name(i, KeyNamePolicy.JAVABEANS_PROPERTY); assertNotNull("Missing method name.", testingMethod); assertNotNull("Missing property name.", property); assertEquals("Wrong property index.", i, accessor.indexOf(property, true)); final Class<?> propertyType = Numbers.primitiveToWrapper(accessor.type(i, TypeValuePolicy.PROPERTY_TYPE)); final Class<?> elementType = Numbers.primitiveToWrapper(accessor.type(i, TypeValuePolicy.ELEMENT_TYPE)); assertNotNull(testingMethod, propertyType); assertNotNull(testingMethod, elementType); Object value = accessor.get(i, instance); if (value == null) { assertFalse("Null values are not allowed to be collections.", isCollection); if (isWritable != accessor.isWritable(i)) { fail("Non writable property: " + accessor + '.' + property); if (Date.class.isAssignableFrom(accessor.type(i, TypeValuePolicy.ELEMENT_TYPE))) { final Object oldValue = accessor.set(i, instance, newValue, PropertyAccessor.RETURN_PREVIOUS); assertEquals("PropertyAccessor.set(…) shall return the value previously returned by get(…).", value, oldValue); value = accessor.get(i, instance); if (isCollection) {
@DependsOnMethod("testSet") public void testSetDeprecated() { final PropertyAccessor accessor = new PropertyAccessor(HardCodedCitations.ISO_19115, CoverageDescription.class, DefaultCoverageDescription.class, DefaultCoverageDescription.class); final int indexOfDeprecated = accessor.indexOf("contentType", true); final int indexOfReplacement = accessor.indexOf("attributeGroup", true); assertTrue("Deprecated elements shall be sorted after non-deprecated ones.", indexOfDeprecated > indexOfReplacement); assertNull("Shall be initially empty.", accessor.set(indexOfDeprecated, instance, CoverageContentType.IMAGE, PropertyAccessor.RETURN_PREVIOUS)); assertEquals(CoverageContentType.IMAGE, accessor.get(indexOfDeprecated, instance)); assertSame(groups, accessor.get(indexOfReplacement, instance)); assertEquals(CoverageContentType.IMAGE, getSingleton(getSingleton(groups).getContentTypes())); assertEquals("Deprecated property shall not be visible.", 1, accessor.count( instance, ValueExistencePolicy.NON_EMPTY, PropertyAccessor.COUNT_SHALLOW));
final String umlIdentifier = (String) expected[i++]; final String sentence = (String) expected[i++]; assertEquals("methodName", methodName, accessor.name(index, KeyNamePolicy.METHOD_NAME)); assertEquals("propertyName", propertyName, accessor.name(index, KeyNamePolicy.JAVABEANS_PROPERTY)); assertEquals("umlIdentifier", umlIdentifier, accessor.name(index, KeyNamePolicy.UML_IDENTIFIER)); assertEquals("sentence", sentence, accessor.name(index, KeyNamePolicy.SENTENCE)); assertEquals("declaringType", declaringType, accessor.type(index, TypeValuePolicy.DECLARING_INTERFACE)); assertEquals(methodName, index, accessor.indexOf(methodName, false)); assertEquals(propertyName, index, accessor.indexOf(propertyName, false)); assertEquals(umlIdentifier, index, accessor.indexOf(umlIdentifier, false)); assertEquals(propertyName, index, accessor.indexOf(propertyName .toLowerCase(Locale.ROOT), false)); assertEquals(umlIdentifier, index, accessor.indexOf(umlIdentifier.toLowerCase(Locale.ROOT), false)); assertEquals(propertyName, propertyType, accessor.type(index, TypeValuePolicy.PROPERTY_TYPE)); assertEquals(umlIdentifier, elementType, accessor.type(index, TypeValuePolicy.ELEMENT_TYPE)); assertEquals("Count of 'get' methods.", i/6, accessor.count());
/** * Tests the equals methods. */ @Test public void testEquals() { DefaultCitation citation = HardCodedCitations.EPSG; final PropertyAccessor accessor = createPropertyAccessor(); assertFalse(accessor.equals(citation, HardCodedCitations.SIS, ComparisonMode.STRICT)); assertTrue (accessor.equals(citation, HardCodedCitations.EPSG, ComparisonMode.STRICT)); // Same test than above, but on a copy of the EPSG constant. citation = new DefaultCitation(HardCodedCitations.EPSG); assertFalse(accessor.equals(citation, HardCodedCitations.SIS, ComparisonMode.STRICT)); assertTrue (accessor.equals(citation, HardCodedCitations.EPSG, ComparisonMode.STRICT)); // Identifiers shall be stored in different collection instances with equal content. final int index = accessor.indexOf("identifiers", true); final Object source = accessor.get(index, HardCodedCitations.EPSG); final Object target = accessor.get(index, citation); assertInstanceOf("identifiers", Collection.class, source); assertInstanceOf("identifiers", Collection.class, target); assertNotSame("Distinct objects shall have distinct collections.", source, target); assertEquals ("The two collections shall have the same content.", source, target); assertEquals ("EPSG", getSingletonCode(target)); // Set the identifiers to null, which should clear the collection. assertEquals("Expected the previous value.", source, accessor.set(index, citation, null, RETURN_PREVIOUS)); final Object value = accessor.get(index, citation); assertNotNull("Should have replaced null by an empty collection.", value); assertTrue("Should have replaced null by an empty collection.", ((Collection<?>) value).isEmpty()); }
this.metadata = metadata; this.accessor = accessor; this.children = new TreeNode[accessor.count()]; final int index = accessor.indexOf(an.name(), false); final Class<?> type = accessor.type(index, TypeValuePolicy.ELEMENT_TYPE); if (type != null && !parent.isMetadata(type) && type == accessor.type(index, TypeValuePolicy.PROPERTY_TYPE)) { titleProperty = index; return;
return count(); final Object value = get(getters[i], metadata); if (!valuePolicy.isSkipped(value)) { switch (mode) { count += (value != null && isCollection(i)) ? Math.max(((Collection<?>) value).size(), 1) : 1; break;
/** * 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; }
/** * Verifies the {@link TitleProperty} annotations. This method verifies that the property exist, * is a singleton, and is not another metadata object. The property should also be mandatory, * but this method does not verify that restriction since there is some exceptions. * * @since 0.8 */ @Test public void testTitlePropertyAnnotation() { for (final Class<?> type : types) { final Class<?> impl = standard.getImplementation(type); if (impl != null) { final TitleProperty an = impl.getAnnotation(TitleProperty.class); if (an != null) { final String name = an.name(); final String message = impl.getSimpleName() + '.' + name; final PropertyAccessor accessor = new PropertyAccessor(standard.getCitation(), type, impl, impl); // Property shall exist. final int index = accessor.indexOf(name, false); assertTrue(message, index >= 0); // Property can not be a metadata. final Class<?> elementType = accessor.type(index, TypeValuePolicy.ELEMENT_TYPE); assertFalse(message, standard.isMetadata(elementType)); // Property shall be a singleton. assertSame(message, elementType, accessor.type(index, TypeValuePolicy.PROPERTY_TYPE)); } } } }
/** * Returns the key corresponding to this entry. */ @Override public String getKey() { return accessor.name(index, keyPolicy); }
/** * Returns the number of elements in this map. * The default implementation returns {@link PropertyAccessor#count()}, which is okay only if * all metadata defined by the standard are included in the map. Subclasses shall override * this method if their map contain only a subset of all possible metadata elements. */ @Override public int size() { return accessor.count(); }
/** * Returns value type as declared in the interface method signature. * It may be a primitive type. */ public Class<?> getValueType() { return accessor.type(index, TypeValuePolicy.PROPERTY_TYPE); }
@Override public Map.Entry<String,ExtendedElementInformation> next() { final ExtendedElementInformation value = accessor.information(index); if (value == null) { // PropertyAccessor.information(int) never return null if the index is valid. throw new NoSuchElementException(); } return new SimpleImmutableEntry<>(accessor.name(index++, keyPolicy), value); } };
/** * 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; }
/** * Implementation of {@link #add(TreeTable.Node)}, also invoked by {@code TreeNode.NewChild}. * This method will attempt to convert the given {@code value} to the expected type. * * @param index the index in the accessor (<em>not</em> the index in this collection). * @param value the property value to add. * @return {@code true} if the metadata changed as a result of this method call. */ final boolean add(final int index, final Object value) throws IllegalStateException { if (ValueExistencePolicy.isNullOrEmpty(value)) { return false; } // Conversion attempt happen in the PropertyAccessor.set(…) method. final Boolean changed = (Boolean) accessor.set(index, metadata, value, PropertyAccessor.APPEND); if (changed == null) { throw new IllegalStateException(Errors.format(Errors.Keys.ValueAlreadyDefined_1, accessor.name(index, KeyNamePolicy.UML_IDENTIFIER))); } if (changed) { modCount++; } return changed; }