org.apache.sis.util.collection.WeakHashSet.unique()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(108)

本文整理了Java中org.apache.sis.util.collection.WeakHashSet.unique()方法的一些代码示例,展示了WeakHashSet.unique()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WeakHashSet.unique()方法的具体详情如下:
包路径:org.apache.sis.util.collection.WeakHashSet
类名称:WeakHashSet
方法名:unique

WeakHashSet.unique介绍

[英]Returns an object equals to element if such an object already exist in this WeakHashSet. Otherwise, adds element to this WeakHashSet. This method is functionally equivalents to the following code: javaif (element != null) T current = get(element); if (current != null) { return current; } else { add(element); } } return element; }
[中]如果此WeakHashSet中已存在对象,则返回一个等于元素的对象。否则,会将元素添加到此WeakHashSet。该方法在功能上等同于以下代码:javaif(element!=null)T current=get(element);如果(current!=null){return current;}else{add(element);}返回元素;}

代码示例

代码示例来源:origin: org.apache.sis.core/sis-referencing

/**
 * Replaces the given transform by a unique instance, if one already exists.
 */
private MathTransform unique(final MathTransform tr) {
  return pool.unique(tr);
}

代码示例来源:origin: apache/sis

/**
 * Replaces the given transform by a unique instance, if one already exists.
 */
private MathTransform unique(final MathTransform tr) {
  return pool.unique(tr);
}

代码示例来源:origin: org.apache.sis.core/sis-utility

/**
 * Returns a unique fraction instance equals to {@code this}.
 * If this method has been invoked previously on another {@code Fraction} with the same value than {@code this},
 * then that previous instance is returned (provided that it has not yet been garbage collected). Otherwise this
 * method adds this fraction to the pool of fractions that may be returned in next {@code unique()} invocations,
 * then returns {@code this}.
 *
 * <p>This method is useful for saving memory when a potentially large amount of {@code Fraction} instances will
 * be kept for a long time and many instances are likely to have the same values.
 * It is usually not worth to invoke this method for short-lived instances.</p>
 *
 * @return a unique instance of a fraction equals to {@code this}.
 */
public Fraction unique() {
  return POOL.unique(this);
}

代码示例来源:origin: apache/sis

/**
 * Returns a unique fraction instance equals to {@code this}.
 * If this method has been invoked previously on another {@code Fraction} with the same value than {@code this},
 * then that previous instance is returned (provided that it has not yet been garbage collected). Otherwise this
 * method adds this fraction to the pool of fractions that may be returned in next {@code unique()} invocations,
 * then returns {@code this}.
 *
 * <p>This method is useful for saving memory when a potentially large amount of {@code Fraction} instances will
 * be kept for a long time and many instances are likely to have the same values.
 * It is usually not worth to invoke this method for short-lived instances.</p>
 *
 * @return a unique instance of a fraction equals to {@code this}.
 */
public Fraction unique() {
  return POOL.unique(this);
}

代码示例来源:origin: apache/sis

/**
 * Invoked after deserialization in order to return a unique instance if possible.
 *
 * @return a unique instance of the deserialized {@code NilReason}.
 * @throws ObjectStreamException required by specification but should never be thrown.
 */
private Object readResolve() throws ObjectStreamException {
  if (reason instanceof String) {
    for (final NilReason candidate : PREDEFINED) {
      if (reason.equals(candidate.reason)) {
        return candidate;
      }
    }
  }
  return POOL.unique(this);
}

代码示例来源:origin: org.apache.sis.core/sis-utility

/**
 * Invoked after deserialization in order to return a unique instance if possible.
 *
 * @return a unique instance of the deserialized {@code NilReason}.
 * @throws ObjectStreamException required by specification but should never be thrown.
 */
private Object readResolve() throws ObjectStreamException {
  if (reason instanceof String) {
    for (final NilReason candidate : PREDEFINED) {
      if (reason.equals(candidate.reason)) {
        return candidate;
      }
    }
  }
  return POOL.unique(this);
}

代码示例来源:origin: org.apache.sis.core/sis-utility

/**
 * Returns the code list for the given ordinal value. This methods depends
 * only on the code list type; it does not depend on the content of this set.
 */
final E valueOf(final int ordinal) {
  E[] array = codes;
  if (array == null || ordinal >= array.length) {
    codes = array = POOL.unique(Types.getCodeValues(elementType));
  }
  return array[ordinal];
}

代码示例来源:origin: apache/sis

/**
 * Returns a unique instance of the given color model. This method is automatically invoked by {@code create(…)} methods
 * in this class. This {@code unique(ColorModel)} method is public for use by color models created by other ways.
 *
 * @param  <T>  the type of the color model to share.
 * @param  cm   the color model for which to get a unique instance.
 * @return a unique (shared) instance of the given color model.
 */
public static <T extends ColorModel> T unique(T cm) {
  ColorModelPatch<T> c = new ColorModelPatch<>(cm);
  c = CACHE.unique(c);
  return c.cm;
}

代码示例来源:origin: apache/sis

/**
 * Returns the code list for the given ordinal value. This methods depends
 * only on the code list type; it does not depend on the content of this set.
 */
final E valueOf(final int ordinal) {
  E[] array = codes;
  if (array == null || ordinal >= array.length) {
    codes = array = POOL.unique(CodeLists.values(elementType));
  }
  return array[ordinal];
}

代码示例来源:origin: apache/sis

/**
 * Creates a member name from the given character sequence and attribute type.
 * The default implementation returns a new or an existing {@link DefaultMemberName} instance.
 *
 * @param  scope  the {@linkplain AbstractName#scope() scope} of the member name to be created,
 *                or {@code null} for a global namespace.
 * @param  name   the member name as a string or an international string.
 * @param  attributeType  the type of the data associated with the record member.
 * @return the member name for the given character sequence.
 *
 * @see Names#createMemberName(CharSequence, String, CharSequence, Class)
 */
public MemberName createMemberName(final NameSpace scope, final CharSequence name, final TypeName attributeType) {
  return pool.unique(new DefaultMemberName(scope, name, attributeType));
}

代码示例来源:origin: apache/sis

/**
 * Returns an unmodifiable implementation of the given parameter value.
 * See class javadoc for more information.
 *
 * @param  <T>        the type of the value stored in the given parameter.
 * @param  parameter  the parameter to make unmodifiable, or {@code null}.
 * @return an unmodifiable implementation of the given parameter, or {@code null} if the given parameter was null.
 */
static <T> UnmodifiableParameterValue<T> create(final ParameterValue<T> parameter) {
  if (parameter == null || parameter instanceof UnmodifiableParameterValue<?>) {
    return (UnmodifiableParameterValue<T>) parameter;
  } else {
    return POOL.unique(new UnmodifiableParameterValue<>(parameter));
  }
}

代码示例来源:origin: org.apache.sis.core/sis-utility

/**
 * Returns a unique instance of the given range, except if the range is empty.
 *
 * <div class="note"><b>Rational:</b>
 * we exclude empty ranges because the {@link Range#equals(Object)} consider them as equal.
 * Consequently if empty ranges were included in the pool, this method would return in some
 * occasions an empty range with different values than the given {@code range} argument.
 * </div>
 */
static <E extends Number & Comparable<? super E>, T extends NumberRange<E>> T unique(T range) {
  if (!range.isEmpty()) {
    range = POOL.unique(range);
  }
  return range;
}

代码示例来源:origin: apache/sis

/**
 * Creates a type name from the given character sequence.
 * The default implementation returns a new or an existing {@link DefaultTypeName} instance.
 *
 * @param  scope  the {@linkplain AbstractName#scope() scope} of the type name to be created,
 *                or {@code null} for a global namespace.
 * @param  name   the type name as a string or an international string.
 * @return the type name for the given character sequence.
 *
 * @see #toTypeName(Class)
 * @see Names#createTypeName(CharSequence, String, CharSequence)
 */
@Override
public TypeName createTypeName(final NameSpace scope, final CharSequence name) {
  return pool.unique(new DefaultTypeName(scope, name));
}

代码示例来源:origin: Geomatys/geotoolkit

/**
 * Creates a new {@code ValueRestriction} instance. If all arguments are {@code null},
 * then this method returns {@code null} meaning "<cite>no restriction</cite>".
 *
 * @param  obligation Whatever the property is mandatory or forbidden, or {@code null} if unknown.
 * @param  range      The range of valid values, or {@code null} if none.
 * @param  validValues An enumeration of valid values, or {@code null} if none.
 * @return The restriction, or {@code null} if none.
 */
private static ValueRestriction create(final Obligation obligation, final NumberRange<?> range, final Set<?> validValues) {
  if (range == null && validValues == null && obligation != Obligation.MANDATORY && obligation != Obligation.FORBIDDEN) {
    return null;
  }
  return POOL.unique(new ValueRestriction(obligation, range, validValues));
}

代码示例来源:origin: org.apache.sis.core/sis-utility

/**
 * Creates a member name from the given character sequence and attribute type.
 * The default implementation returns a new or an existing {@link DefaultMemberName} instance.
 *
 * @param  scope  the {@linkplain AbstractName#scope() scope} of the member name to be created,
 *                or {@code null} for a global namespace.
 * @param  name   the member name as a string or an international string.
 * @param  attributeType  the type of the data associated with the record member.
 * @return the member name for the given character sequence.
 *
 * @see Names#createMemberName(CharSequence, String, CharSequence, Class)
 */
public MemberName createMemberName(final NameSpace scope, final CharSequence name, final TypeName attributeType) {
  return pool.unique(new DefaultMemberName(scope, name, attributeType));
}

代码示例来源:origin: org.apache.sis.core/sis-referencing

/**
 * Returns an unmodifiable implementation of the given parameter value.
 * See class javadoc for more information.
 *
 * @param  <T>        the type of the value stored in the given parameter.
 * @param  parameter  the parameter to make unmodifiable, or {@code null}.
 * @return an unmodifiable implementation of the given parameter, or {@code null} if the given parameter was null.
 */
static <T> UnmodifiableParameterValue<T> create(final ParameterValue<T> parameter) {
  if (parameter == null || parameter instanceof UnmodifiableParameterValue<?>) {
    return (UnmodifiableParameterValue<T>) parameter;
  } else {
    return POOL.unique(new UnmodifiableParameterValue<>(parameter));
  }
}

代码示例来源:origin: apache/sis

/**
 * Returns a unique instance of the given range, except if the range is empty.
 *
 * <div class="note"><b>Rational:</b>
 * we exclude empty ranges because the {@link Range#equals(Object)} consider them as equal.
 * Consequently if empty ranges were included in the pool, this method would return in some
 * occasions an empty range with different values than the given {@code range} argument.
 * </div>
 *
 * We use this method only for caching range of wrapper of primitive types ({@link Byte},
 * {@link Short}, <i>etc.</i>) because those type are known to be immutable.
 */
static <E extends Number & Comparable<? super E>, T extends NumberRange<E>> T unique(T range) {
  if (!range.isEmpty()) {
    range = POOL.unique(range);
  }
  return range;
}

代码示例来源:origin: org.apache.sis.core/sis-utility

/**
 * Creates a type name from the given character sequence.
 * The default implementation returns a new or an existing {@link DefaultTypeName} instance.
 *
 * @param  scope  the {@linkplain AbstractName#scope() scope} of the type name to be created,
 *                or {@code null} for a global namespace.
 * @param  name   the type name as a string or an international string.
 * @return the type name for the given character sequence.
 *
 * @see #toTypeName(Class)
 * @see Names#createTypeName(CharSequence, String, CharSequence)
 */
@Override
public TypeName createTypeName(final NameSpace scope, final CharSequence name) {
  return pool.unique(new DefaultTypeName(scope, name));
}

代码示例来源:origin: apache/sis

/**
 * Reads all the data for this variable and returns them as an array of a Java primitive type.
 * Multi-dimensional variables are flattened as a one-dimensional array (wrapped in a vector).
 * This method may replace fill/missing values by NaN values and caches the returned vector.
 */
@Override
@SuppressWarnings("ReturnOfCollectionOrArrayField")
public Vector read() throws IOException {
  if (values == null) {
    final Array array = variable.read();                // May be already cached by the UCAR library.
    values = createDecimalVector(get1DJavaArray(array), variable.isUnsigned());
    values = SHARED_VECTORS.unique(values);
  }
  return values;
}

代码示例来源:origin: apache/sis

/**
   * Tests with array elements.
   */
  @Test
  @DependsOnMethod("testStrongReferences")
  public void testWithArrayElements() {
    final WeakHashSet<int[]> weakSet = new WeakHashSet<>(int[].class);
    final int[] array = new int[] {2, 5, 3};
    assertTrue (weakSet.add(array));
    assertFalse(weakSet.add(array));
    assertFalse(weakSet.add(array.clone()));
    assertTrue (weakSet.add(new int[] {2, 5, 4}));
    assertSame (array, weakSet.unique(array.clone()));
  }
}

相关文章

微信公众号

最新文章

更多