/** * Creates a new parameter descriptor for the given units. * * @param units the units. */ public EPSGParameterDomain(final Set<Unit<?>> units) { super(Double.class, null, false, null, false); this.units = CollectionsExt.unmodifiableOrCopy(units); } }
/** * Creates a new parameter descriptor for the given units. * * @param units the units. */ public EPSGParameterDomain(final Set<Unit<?>> units) { super(Double.class, null, false, null, false); this.units = CollectionsExt.unmodifiableOrCopy(units); } }
/** * Returns a unmodifiable version of the given set. * This method is different than the standard {@link Collections#unmodifiableSet(Set)} * in that it tries to returns a more efficient object when there is zero or one element. * Such small set occurs frequently in Apache SIS, especially for * {@link org.apache.sis.referencing.AbstractIdentifiedObject} names or identifiers. * * <p><em>The set returned by this method may or may not be a view of the given set</em>. * Consequently this method shall be used <strong>only</strong> if the given set will * <strong>not</strong> be modified after this method call. In case of doubt, use the * standard {@link Collections#unmodifiableSet(Set)} method instead.</p> * * @param <E> The type of elements in the set. * @param set The set to make unmodifiable, or {@code null}. * @return A unmodifiable version of the given set, or {@code null} if the given set was null. */ public static <E> Set<E> unmodifiableOrCopy(Set<E> set) { return CollectionsExt.unmodifiableOrCopy(set); }
/** * Returns a unmodifiable version of the given map. * This method is different than the standard {@link Collections#unmodifiableMap(Map)} * in that it tries to returns a more efficient object when there is zero or one entry. * Such small maps occur frequently in Apache SIS. * * <p><em>The map returned by this method may or may not be a view of the given map</em>. * Consequently this method shall be used <strong>only</strong> if the given map will * <strong>not</strong> be modified after this method call. In case of doubt, use the * standard {@link Collections#unmodifiableMap(Map)} method instead.</p> * * @param <K> The type of keys in the map. * @param <V> The type of values in the map. * @param map The map to make unmodifiable, or {@code null}. * @return A unmodifiable version of the given map, or {@code null} if the given map was null. */ public static <K,V> Map<K,V> unmodifiableOrCopy(Map<K,V> map) { return CollectionsExt.unmodifiableOrCopy(map); }
/** * {@inheritDoc} */ @Override public boolean transition(final State target) { final Collection<Identifier> p = identifiers; final boolean changed = super.transition(target); if (changed) { /* * The 'identifiers' collection will have been replaced by an unmodifiable collection if * subclass has an "identifiers" property. If this is not the case, then the collection * is unchanged (or null) so we have to make it unmodifiable here. */ if (p != null && p == identifiers) { if (p instanceof Set<?>) { identifiers = CollectionsExt.unmodifiableOrCopy((Set<Identifier>) p); } else if (p instanceof List<?>) { identifiers = CollectionsExt.unmodifiableOrCopy((List<Identifier>) p); } else { identifiers = Collections.unmodifiableCollection(p); } } } return changed; }
set.remove(null); return unmodifiableOrCopy(set);
set.remove(null); return unmodifiableOrCopy(set);
/** * Returns the code spaces of all factories given to the constructor. * * <div class="note"><b>Implementation note:</b> * the current implementation may be relatively costly since it implies instantiation of all factories. * </div> * * @return the code spaces of all factories. */ @Override @SuppressWarnings("ReturnOfCollectionOrArrayField") public Set<String> getCodeSpaces() { Set<String> union = codeSpaces; if (union == null) { union = new LinkedHashSet<>(); for (final Iterator<AuthorityFactory> it = getAllFactories(); it.hasNext();) { union.addAll(getCodeSpaces(it.next())); } codeSpaces = union = CollectionsExt.unmodifiableOrCopy(union); } return union; }
nodataValues = CollectionsExt.unmodifiableOrCopy(pads);
/** * Returns the code spaces of all factories given to the constructor. * * <div class="note"><b>Implementation note:</b> * the current implementation may be relatively costly since it implies instantiation of all factories. * </div> * * @return the code spaces of all factories. */ @Override @SuppressWarnings("ReturnOfCollectionOrArrayField") public Set<String> getCodeSpaces() { Set<String> union = codeSpaces; if (union == null) { union = new LinkedHashSet<>(); for (final Iterator<AuthorityFactory> it = getAllFactories(); it.hasNext();) { union.addAll(getCodeSpaces(it.next())); } codeSpaces = union = CollectionsExt.unmodifiableOrCopy(union); } return union; }
if (collection != null) { if (collection instanceof Set<?>) { return unmodifiableOrCopy((Set<E>) collection);
/** * Declares this metadata and all its properties as unmodifiable. Any attempt to modify a property * after this method call will throw an {@link org.apache.sis.metadata.UnmodifiableMetadataException}. * If this metadata is already unmodifiable, then this method does nothing. * * <p>Subclasses usually do not need to override this method since the default implementation * performs most of its work using Java reflection.</p> */ @Override public void freeze() { if (isModifiable()) { final Collection<Identifier> p = identifiers; super.freeze(); /* * The 'identifiers' collection will have been replaced by an unmodifiable collection if * subclass has an "identifiers" property. If this is not the case, then the collection * is unchanged (or null) so we have to make it unmodifiable here. */ if (p == identifiers) { identifiers = CollectionsExt.unmodifiableOrCopy(p); // Null safe. } } }
i++; memberIndices = CollectionsExt.unmodifiableOrCopy(memberIndices); baseValueClass = (baseValueClass != null) ? Numbers.wrapperToPrimitive(baseValueClass) : Object.class; return types;
/** * Stores the given result in the cache. * This method shall be invoked only when {@link #getSearchDomain()} is not {@link Domain#DECLARATION}. */ @Override final Set<IdentifiedObject> cache(final IdentifiedObject object, Set<IdentifiedObject> result) { final Map<IdentifiedObject,FindEntry> findPool = ((ConcurrentAuthorityFactory<?>) factory).findPool; result = CollectionsExt.unmodifiableOrCopy(result); FindEntry entry = new FindEntry(); synchronized (findPool) { final FindEntry c = findPool.putIfAbsent(object, entry); if (c != null) { entry = c; // May happen if the same set has been computed in another thread. } // 'finder' should never be null since this method is not invoked directly by this Finder. result = entry.set(finder.isIgnoringAxes(), result, object == searching); } return result; }
i++; memberIndices = CollectionsExt.unmodifiableOrCopy(memberIndices); baseValueClass = (baseValueClass != null) ? Numbers.wrapperToPrimitive(baseValueClass) : Object.class; return types;
components = CollectionsExt.unmodifiableOrCopy(components); dim = new UnitDimension(components); if (!Units.initialized) {
if (dim == null) { components.replaceAll((c, power) -> power.unique()); components = CollectionsExt.unmodifiableOrCopy(components); dim = new UnitDimension(components); if (!Units.initialized) {
if (state == COMPLETABLE) { if (useSet) { target = CollectionsExt.unmodifiableOrCopy((Set<E>) target); } else { target = CollectionsExt.unmodifiableOrCopy((List<E>) target);
/** * Stores the given result in the cache. * This method shall be invoked only when {@link #getSearchDomain()} is not {@link Domain#DECLARATION}. */ @Override final Set<IdentifiedObject> cache(final IdentifiedObject object, Set<IdentifiedObject> result) { final Map<IdentifiedObject,FindEntry> findPool = ((ConcurrentAuthorityFactory<?>) factory).findPool; result = CollectionsExt.unmodifiableOrCopy(result); FindEntry entry = new FindEntry(); synchronized (findPool) { final FindEntry c = JDK8.putIfAbsent(findPool, object, entry); if (c != null) { entry = c; // May happen if the same set has been computed in another thread. } // 'finder' should never be null since this method is not invoked directly by this Finder. result = entry.set(finder.isIgnoringAxes(), result, object == searching); } return result; }
entry.setValue(clone(entry.getValue())); return CollectionsExt.unmodifiableOrCopy(map);