org.geotools.util.Range类的使用及代码示例

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

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

Range介绍

[英]A range between a minimum and maximum comparable. The minimum/maximum may be included, excluded or unbounded. The later case is indicated by null values on one or both ends.

This class is a method compatible replacement for the javax.media.jai.util.Range class with the following differences:

  • Unbounded ranges (i.e. null minimal or maximal values) are considered exclusive rather than inclusive, since an iteration over the values will never reach the infinite bound. This interpretation brings some simplification in implementation and usage (e.g. a loop over the values should not attempt to process the nullvalue).
  • #subtract returns an empty array if the whole range is subtracted.

The exact #getElementClass doesn't need to be known at compile time. Widening conversions are allowed as needed (subclasses like NumberRange do that). This class is weakly parameterized in order to allow this flexibility. If any constructor or method is invoked with an argument value of illegal class, then an IllegalArgumentException is thrown. The ClassCastException is thrown only in case of bug in the Range class or subclasses implementation.
[中]最小值和最大值之间的范围。最小值/最大值可以包括、排除或不受限制。后一种情况由一端或两端的空值表示。
这个类是javax的方法兼容的替代品。媒体洁。util。具有以下差异的范围类:
*无界范围(即零最小值或最大值)被视为“独占”而非“包含”,因为对这些值的迭代永远不会达到无限界。这种解释在实现和使用方面带来了一些简化(例如,值上的循环不应试图处理空值)。
*如果减去整个范围,则#subtract返回空数组。
编译时不需要知道确切的#getElementClass。可以根据需要扩大转换范围(NumberRange这样的子类可以做到这一点)。为了允许这种灵活性,这个类被弱参数化。如果使用非法类的参数值调用任何构造函数或方法,则会引发IllegalArgumentException。ClassCastException仅在Range类或子类实现中出现错误时才会抛出。

代码示例

代码示例来源: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

/**
 * Creates a new range using the same element class than this range. This method will be
 * overriden by subclasses in order to create a range of a more specific type.
 */
Range<T> create(
    final T minValue,
    final boolean isMinIncluded,
    final T maxValue,
    final boolean isMaxIncluded) {
  return new Range<T>(elementClass, minValue, isMinIncluded, maxValue, isMaxIncluded);
}

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

if (!intersects(range)) {
  subtract = this;
} else {
  final boolean clipMin = compareMinTo(range.minValue, range.isMinIncluded ? 0 : +1) >= 0;
  final boolean clipMax = compareMaxTo(range.maxValue, range.isMaxIncluded ? 0 : -1) <= 0;
  if (clipMin) {
    if (clipMax) {
      assert range.contains(this) : range;
      return newArray(0);
    subtract = create(range.maxValue, !range.isMaxIncluded, maxValue, isMaxIncluded);
  } else {
    if (!clipMax) {
      final Range<T>[] array = newArray(2);
      array[0] =
          create(minValue, isMinIncluded, range.minValue, !range.isMinIncluded);
      array[1] =
          create(range.maxValue, !range.isMaxIncluded, maxValue, isMaxIncluded);
      return array;
    subtract = create(minValue, isMinIncluded, range.minValue, !range.isMinIncluded);
assert contains(subtract) : subtract;
assert !subtract.intersects(range) : subtract;
final Range<T>[] array = newArray(1);
array[0] = subtract;
return array;

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

public Range getSearchRange(Object value) {
  if (value instanceof Range) {
    Range range = (Range) value;
    Range before = getSearchRangeOnSingleValue(range.getMinValue());
    Range after = getSearchRangeOnSingleValue(range.getMaxValue());
    return before.union(after);
  } else {
    return getSearchRangeOnSingleValue(value);
  }
}

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

/**
 * Implementation of {@link #union(Range)} to be invoked directly by subclasses. "NC" stands for
 * "No Cast" - this method do not try to cast the value to a compatible type.
 */
final Range<?> unionNC(final Range<? extends T> range) throws IllegalArgumentException {
  final Range<? extends T> union, min, max;
  min = compareMinTo(range.minValue, range.isMinIncluded ? 0 : +1) > 0 ? range : this;
  max = compareMaxTo(range.maxValue, range.isMaxIncluded ? 0 : -1) < 0 ? range : this;
  if (min == max) {
    union = min;
  } else {
    union = create(min.minValue, min.isMinIncluded, max.maxValue, max.isMaxIncluded);
  }
  assert union.contains(min) : min;
  assert union.contains(max) : max;
  return union;
}

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

public SymbolizerKey(Symbolizer symbolizer, Range scaleRange) {
  this.symbolizer = symbolizer;
  if (scaleRange == null) {
    minScale = 0;
    maxScale = Double.POSITIVE_INFINITY;
  } else {
    minScale = ((Number) scaleRange.getMinValue()).doubleValue();
    maxScale = ((Number) scaleRange.getMaxValue()).doubleValue();
  }
}

代码示例来源: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);
  }
}

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

Range rb = (Range) b;
if (ra.intersects(rb)) {
  return 0;
} else if (ra.getMinValue().compareTo(rb.getMaxValue()) >= 0) {
  return 1;
} else {

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

if (scaleRange != null && scaleRange.isEmpty()) {
  return;
  Double minValue = scaleRange.getMinValue();
  if (minValue != null && minValue > 0) {
    ruleBuilder.min(minValue);
  Double maxValue = scaleRange.getMaxValue();
  if (maxValue != null && maxValue < Double.POSITIVE_INFINITY) {
    ruleBuilder.max(maxValue);

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

@Override
  public int compare(Range<T> o1, Range<T> o2) {
    if (o1 == null) {
      return o2 != null ? -1 : 0;
    } else if (o2 == null) {
      return 1;
    } else if (o1.getMinValue() == null) {
      return o2.getMinValue() == null ? 0 : -1;
    } else if (o2.getMinValue() == null) {
      return 1;
    } else {
      return o1.getMinValue().compareTo(o2.getMinValue());
    }
  }
}

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

/** Returns the end time. */
  @Override
  public Date getMaxValue() {
    return clone(super.getMaxValue());
  }
}

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

private Filter toGreaterFilter(FilterFactory ff, Expression variable, Range<T> range) {
  if (range.isMinIncluded()) {
    return ff.greaterOrEqual(variable, ff.literal(range.getMinValue()));
  } else {
    return ff.greater(variable, ff.literal(range.getMinValue()));
  }
}

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

private Filter toLessFilter(FilterFactory ff, Expression variable, Range<T> range) {
  if (range.isMaxIncluded()) {
    return ff.lessOrEqual(variable, ff.literal(range.getMaxValue()));
  } else {
    return ff.less(variable, ff.literal(range.getMaxValue()));
  }
}

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

/**
 * If the specified value is inside a range, returns the index of this range. Otherwise, returns
 * {@code -1}.
 *
 * @param value The value to search.
 * @return The index of the range which contains this value, or -1 if there is no such range.
 */
public int indexOfRange(final Comparable value) {
  int index = binarySearch(toArrayElement(value));
  if (index < 0) {
    // Found an insertion point. Make sure that the insertion
    // point is inside a range (i.e. before the maximum value).
    index = ~index; // Tild sign, not minus.
    if ((index & 1) == 0) {
      return -1;
    }
  }
  index /= 2; // Round toward 0 (odd index are maximum values).
  assert newRange(get(2 * index), get(2 * index + 1)).contains(value) : value;
  return index;
}

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

private boolean rangeFilterAccepts(Range rangeFilter, Object domainValue) {
  if (rangeFilter == null) {
    return true;
  }
  if (domainValue instanceof Range) {
    return rangeFilter.intersects((Range) domainValue);
  } else {
    return rangeFilter.contains((Comparable) domainValue);
  }
}

代码示例来源: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: geoserver/geoserver

FF.between(
        attribute,
        FF.literal(range.getMinValue()),
        FF.literal(range.getMaxValue()));
query.setFilter(rangeFilter);
query.setMaxFeatures(maxEntries);

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

/** Returns the start time. */
@Override
public Date getMinValue() {
  return clone(super.getMinValue());
}

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

/**
   * Returns the end time.
   */
  @Override
  public Date getMaxValue() {
    return clone(super.getMaxValue());
  }
}

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

/**
 * Implementation of {@link #union(Range)} to be invoked directly by subclasses.
 * "NC" stands for "No Cast" - this method do not try to cast the value to a compatible type.
 */
final Range<?> unionNC(final Range<? extends T> range) throws IllegalArgumentException {
  final Range<? extends T> union, min, max;
  min = compareMinTo(range.minValue, range.isMinIncluded ? 0 : +1) > 0 ? range : this;
  max = compareMaxTo(range.maxValue, range.isMaxIncluded ? 0 : -1) < 0 ? range : this;
  if (min == max) {
    union = min;
  } else {
    union = create(min.minValue, min.isMinIncluded, max.maxValue, max.isMaxIncluded);
  }
  assert union.contains(min) : min;
  assert union.contains(max) : max;
  return union;
}

相关文章