Clamp values.

@param x     Value.
@param range Range.
@return Value.
176295
public static double Clamp(double x, DoubleRange range) {
        return Clamp(x, range.getMin(), range.getMax());
    }
185329
def clip( range = 0 .. 0xFF )
      if range.exclude_end?
        raise "Clipping does not support ranges with end value " +
              "excluded (such as #{range})"
      end
      collect { |x| x.major( range.begin ).minor range.end }
    end
6580
public static <T extends Comparable<T>> RangeSet<T> unionRanges(final Iterable<Range<T>> ranges)
  {
    RangeSet<T> rangeSet = null;
    for (Range<T> range : ranges) {
      if (rangeSet == null) {
        rangeSet = TreeRangeSet.create();
      }
      rangeSet.add(range);
    }
    return rangeSet;
  }
434212
public boolean inRanges(Instance instance, double[][] ranges) {
    boolean isIn = true;
    
    // updateRangesFirst must have been called on ranges
    for (int j = 0; isIn && (j < ranges.length); j++) {
      if (!instance.isMissing(j)) {
        double value = instance.value(j);
        isIn = value <= ranges[j][R_MAX];
        if (isIn) isIn = value >= ranges[j][R_MIN];
      }
    }
    
    return isIn;
  }
1285662
public static int clamp(int x, int min, int max) {
		if (x > max) return max;
		if (x < min) return min;
		return x;
	}
489975
public static boolean[] updateRanges(boolean[] range, GrammarRules grammar) {
    boolean[] res = Arrays.copyOf(range, range.length);
    for (GrammarRuleRecord r : grammar) {
      if (0 == r.getRuleNumber()) {
        continue;
      }
      res = updateRanges(res, r.getRuleIntervals());
    }
    return res;
  }
631973
public static float updateFloat(float value, float range) {
		range = range == 0 ? (float) (0.1 * value) : range;
		float min = value - range;
		float max = value + range;
		return nextFloat(min, max);
	}
650577
def set_range_x(self,val):
        
        d = self.declaration
        if d.auto_range[0]:
            return
        self.widget.setXRange(*val,padding=0)
396132
public static int getRandomInteger(Range range)
    {
        Check.notNull(range);

        return getRandomInteger(range.getMin(), range.getMax());
    }
854371
function clampSelf(low, high) {
         return this._set(me.Math.clamp(this.x, low, high), me.Math.clamp(this.y, low, high));
       }
323491
public static <C extends Comparable> C center(final Range<C> range) {
        checkNotNull(range);
        if (!range.hasLowerBound() && !range.hasUpperBound()) {
            throw new IllegalStateException("cannot find the center of a range without bounds");
        }
        if (!range.hasLowerBound()) {
            return range.upperEndpoint();
        }
        if (!range.hasUpperBound()) {
            return range.lowerEndpoint();
        }
        C lowerEndpoint = range.lowerEndpoint();
        C upperEndpoint = range.upperEndpoint();

        if (upperEndpoint instanceof Integer) {
            Integer upper = (Integer) upperEndpoint;
            Integer lower = (Integer) lowerEndpoint;
            return (C) Integer.valueOf((upper.intValue() + lower.intValue()) / 2);
        }
        if (upperEndpoint instanceof Long) {
            Long upper = (Long) upperEndpoint;
            Long lower = (Long) lowerEndpoint;
            return (C) Long.valueOf((upper.longValue() + lower.longValue()) / 2L);
        }
        if (upperEndpoint instanceof BigInteger) {
            BigInteger upper = (BigInteger) upperEndpoint;
            BigInteger lower = (BigInteger) lowerEndpoint;
            BigInteger two = BigInteger.valueOf(2L);
            return (C) upper.subtract(lower).divide(two);
        }

        // todo:  could potentially calculate the center of any range with a discrete domain
        throw new IllegalStateException("cannot find the center of a range whose endpoint type is not Integer, Long, or BigInteger");
    }
1245184
@SuppressWarnings("unchecked")
    public static List<Boolean> getAt(boolean[] array, ObjectRange range) {
        return primitiveArrayGet(array, range);
    }
1159169
public boolean IsOverlapping(IntRange range) {
        return ((isInside(range.min)) || (isInside(range.max)) ||
                (range.isInside(min)) || (range.isInside(max)));
    }
394236
public static Set<Integer> parseRange(String range) {
        if (range == null) {
            return Collections.emptySet();
        }
        Set<Integer> ret = new LinkedHashSet<>();
        StringTokenizer stringTokenizer = new StringTokenizer(range, String.format("%s%s", COMMA, DASH), true);
        Integer from = null;
        Integer to = null;
        boolean rangeStarted = false;
        while (stringTokenizer.hasMoreTokens()) {
            String token = stringTokenizer.nextToken();
            if (isValueDelimiter(token)) {
                ret.addAll(fromToAsSet(from, to));
                from = null;
                to = null;
                rangeStarted = false;
            } else if (isRangeDelimiter(token)) {
                rangeStarted = true;
            } else {
                String trimmedValue = token.trim();
                if (!isPositiveInt(trimmedValue)) {
                    throw new IllegalArgumentException("Range values should be positive numbers.");
                }
                Integer parsedInteger = Integer.parseUnsignedInt(trimmedValue);
                if (rangeStarted) {
                    to = parsedInteger;
                } else {
                    from = parsedInteger;
                }
            }
            if (from != null) {
                ret.addAll(fromToAsSet(from, to));
            }
        }

        return ret;
    }
1100702
def clamp_within_range(self, x, y):
        
        x = int(x)
        y = int(y)

        if x < 0:
            x = 0
        if y < 0:
            y = 0
        if x > self.size_in_tiles.X:
            x = self.size_in_tiles.X
        if y > self.size_in_tiles.Y:
            y = self.size_in_tiles.Y

        return x, y
1276064
private boolean isWithinRange(T value) {
        if (getMinInclusive() != null
                && compareTo(getMinInclusive(), value) > 0) {
            return false;
        }
        if (getMaxInclusive() != null
                && compareTo(getMaxInclusive(), value) < 0) {
            return false;
        }
        return true;
    }
1349033
@SuppressWarnings("unchecked")
    public static List<Float> getAt(float[] array, Range range) {
        return primitiveArrayGet(array, range);
    }