org.geotools.util.Range.getElementClass()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(5.0k)|赞(0)|评价(0)|浏览(107)

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

Range.getElementClass介绍

[英]Returns the class of elements in this range. The element class extends Comparable.
[中]返回此范围内的元素类。element类扩展了Comparable。

代码示例

代码示例来源:origin: geotools/geotools

/**
 * Casts the specified range to the specified type. If this class is associated to a unit of
 * measurement, then this method convert the {@code range} units to the same units than this
 * instance. This method is overriden by {@link MeasurementRange} only in the way described
 * above.
 *
 * @param type The class to cast to. Must be one of {@link Byte}, {@link Short}, {@link
 *     Integer}, {@link Long}, {@link Float} or {@link Double}.
 * @return The casted range, or {@code range} if no cast is needed.
 * @throws IllegalArgumentException if the values are not convertible to the specified class.
 */
<N extends Number & Comparable<? super N>> NumberRange<N> convertAndCast(
    final Range<? extends Number> range, final Class<N> type)
    throws IllegalArgumentException {
  if (type.equals(range.getElementClass())) {
    @SuppressWarnings({
      "unchecked",
      "rawtypes"
    }) // Safe because we checked in the line just above.
    final NumberRange<N> cast = (NumberRange) wrap((Range) range);
    return cast;
  }
  return new NumberRange<N>(type, range);
}

代码示例来源:origin: geotools/geotools

/**
 * Returns the smallest sample dimension type capable to hold the specified range of values.
 *
 * @param range The range of values.
 * @return The smallest sample dimension type for the specified range.
 */
public static SampleDimensionType getSampleDimensionType(final Range<?> range) {
  final Class<?> type = range.getElementClass();
  if (Double.class.isAssignableFrom(type)) {
    return REAL_64BITS;
  }
  if (Float.class.isAssignableFrom(type)) {
    return REAL_32BITS;
  }
  long min = ((Number) range.getMinValue()).longValue();
  long max = ((Number) range.getMaxValue()).longValue();
  if (!range.isMinIncluded()) min++;
  if (!range.isMaxIncluded()) max--;
  return getSampleDimensionType(min, max);
}

代码示例来源:origin: geotools/geotools

/**
 * Constructs a range with the same type and the same values than the specified range. This is a
 * copy constructor.
 *
 * @param range The range to copy. The elements must be {@link Number} instances.
 * @since 2.4
 */
public NumberRange(final Range<T> range) {
  super(
      range.getElementClass(),
      range.getMinValue(),
      range.isMinIncluded(),
      range.getMaxValue(),
      range.isMaxIncluded());
}

代码示例来源:origin: geotools/geotools

Range<T> union =
    new Range<T>(
        range.getElementClass(),
        (T) range.getMinValue(),
        range.isMinIncluded(),

代码示例来源:origin: org.geotools/gt-metadata

/**
 * Casts the specified range to the specified type. If this class is associated to a unit of
 * measurement, then this method convert the {@code range} units to the same units than this
 * instance. This method is overriden by {@link MeasurementRange} only in the way described
 * above.
 *
 * @param  type The class to cast to. Must be one of {@link Byte}, {@link Short},
 *              {@link Integer}, {@link Long}, {@link Float} or {@link Double}.
 * @return The casted range, or {@code range} if no cast is needed.
 * @throws IllegalArgumentException if the values are not convertible to the specified class.
 */
<N extends Number & Comparable<? super N>>
NumberRange<N> convertAndCast(final Range<? extends Number> range, final Class<N> type)
    throws IllegalArgumentException
{
  if (type.equals(range.getElementClass())) {
    @SuppressWarnings("unchecked") // Safe because we checked in the line just above.
    final NumberRange<N> cast = (NumberRange<N>) wrap((Range) range);
    return cast;
  }
  // TODO: Remove the (Range) cast when we will be allowed to compile for Java 6.
  return new NumberRange<N>(type, (Range) range);
}

代码示例来源:origin: org.geotools/gt-coverage

/**
 * Returns the smallest sample dimension type capable to hold the specified range of values.
 *
 * @param  range The range of values.
 * @return The smallest sample dimension type for the specified range.
 */
public static SampleDimensionType getSampleDimensionType(final Range<?> range) {
  final Class<?> type = range.getElementClass();
  if (Double.class.isAssignableFrom(type)) {
    return REAL_64BITS;
  }
  if (Float.class.isAssignableFrom(type)) {
    return REAL_32BITS;
  }
  long min = ((Number) range.getMinValue()).longValue();
  long max = ((Number) range.getMaxValue()).longValue();
  if (!range.isMinIncluded()) min++;
  if (!range.isMaxIncluded()) max--;
  return getSampleDimensionType(min, max);
}

代码示例来源:origin: org.geotools/gt-metadata

/**
 * Constructs a range with the same type and the same values than the
 * specified range. This is a copy constructor.
 *
 * @param range The range to copy. The elements must be {@link Number} instances.
 *
 * @since 2.4
 */
public NumberRange(final Range<T> range) {
  super(range.getElementClass(),
     range.getMinValue(), range.isMinIncluded(),
     range.getMaxValue(), range.isMaxIncluded());
}

代码示例来源:origin: org.geoserver/gs-wms

@Override
public Object getDefaultValue(
    ResourceInfo resource, String dimensionName, DimensionInfo dimension, Class clz) {
  if (value instanceof Range) {
    Range r = (Range) value;
    if (clz.isAssignableFrom(r.getElementClass())) {
      return r;
    } else {
      Comparable min = (Comparable) Converters.convert(r.getMinValue(), clz);
      Comparable max = (Comparable) Converters.convert(r.getMaxValue(), clz);
      return new Range(clz, min, max);
    }
  } else {
    return Converters.convert(this.value, clz);
  }
}

相关文章