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

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

本文整理了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

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

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

  1. /**
  2. * Returns the smallest sample dimension type capable to hold the specified range of values.
  3. *
  4. * @param range The range of values.
  5. * @return The smallest sample dimension type for the specified range.
  6. */
  7. public static SampleDimensionType getSampleDimensionType(final Range<?> range) {
  8. final Class<?> type = range.getElementClass();
  9. if (Double.class.isAssignableFrom(type)) {
  10. return REAL_64BITS;
  11. }
  12. if (Float.class.isAssignableFrom(type)) {
  13. return REAL_32BITS;
  14. }
  15. long min = ((Number) range.getMinValue()).longValue();
  16. long max = ((Number) range.getMaxValue()).longValue();
  17. if (!range.isMinIncluded()) min++;
  18. if (!range.isMaxIncluded()) max--;
  19. return getSampleDimensionType(min, max);
  20. }

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

  1. /**
  2. * Constructs a range with the same type and the same values than the specified range. This is a
  3. * copy constructor.
  4. *
  5. * @param range The range to copy. The elements must be {@link Number} instances.
  6. * @since 2.4
  7. */
  8. public NumberRange(final Range<T> range) {
  9. super(
  10. range.getElementClass(),
  11. range.getMinValue(),
  12. range.isMinIncluded(),
  13. range.getMaxValue(),
  14. range.isMaxIncluded());
  15. }

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

  1. Range<T> union =
  2. new Range<T>(
  3. range.getElementClass(),
  4. (T) range.getMinValue(),
  5. range.isMinIncluded(),

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

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

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

  1. /**
  2. * Returns the smallest sample dimension type capable to hold the specified range of values.
  3. *
  4. * @param range The range of values.
  5. * @return The smallest sample dimension type for the specified range.
  6. */
  7. public static SampleDimensionType getSampleDimensionType(final Range<?> range) {
  8. final Class<?> type = range.getElementClass();
  9. if (Double.class.isAssignableFrom(type)) {
  10. return REAL_64BITS;
  11. }
  12. if (Float.class.isAssignableFrom(type)) {
  13. return REAL_32BITS;
  14. }
  15. long min = ((Number) range.getMinValue()).longValue();
  16. long max = ((Number) range.getMaxValue()).longValue();
  17. if (!range.isMinIncluded()) min++;
  18. if (!range.isMaxIncluded()) max--;
  19. return getSampleDimensionType(min, max);
  20. }

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

  1. /**
  2. * Constructs a range with the same type and the same values than the
  3. * specified range. This is a copy constructor.
  4. *
  5. * @param range The range to copy. The elements must be {@link Number} instances.
  6. *
  7. * @since 2.4
  8. */
  9. public NumberRange(final Range<T> range) {
  10. super(range.getElementClass(),
  11. range.getMinValue(), range.isMinIncluded(),
  12. range.getMaxValue(), range.isMaxIncluded());
  13. }

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

  1. @Override
  2. public Object getDefaultValue(
  3. ResourceInfo resource, String dimensionName, DimensionInfo dimension, Class clz) {
  4. if (value instanceof Range) {
  5. Range r = (Range) value;
  6. if (clz.isAssignableFrom(r.getElementClass())) {
  7. return r;
  8. } else {
  9. Comparable min = (Comparable) Converters.convert(r.getMinValue(), clz);
  10. Comparable max = (Comparable) Converters.convert(r.getMaxValue(), clz);
  11. return new Range(clz, min, max);
  12. }
  13. } else {
  14. return Converters.convert(this.value, clz);
  15. }
  16. }

相关文章