Create and return a new node for the specified ranges.

@param ranges ranges
@return a new node for the specified ranges
504333
private Node createNode(final Iterable<Range<C>> ranges) {
        Range<C> span = Iterables.getFirst(ranges, null);
        if (span == null) {
            return null;
        }
        for (Range<C> range : ranges) {
            checkNotNull(range, "ranges must not contain null ranges");
            span = range.span(span);
        }
        if (span.isEmpty()) {
            return null;
        }
        C center = Ranges.center(span);
        List<Range<C>> left = Lists.newArrayList();
        List<Range<C>> right = Lists.newArrayList();
        List<Range<C>> overlap = Lists.newArrayList();
        for (Range<C> range : ranges) {
            if (Ranges.isLessThan(range, center)) {
                left.add(range);
            }
            else if (Ranges.isGreaterThan(range, center)) {
                right.add(range);
            }
            else {
                overlap.add(range);
            }
        }
        return new Node(center, createNode(left), createNode(right), overlap);
    }
537070
public void add(LCMSRange range) {
    Integer msLevel = range.getMsLevel();
    DoubleRange mzRange = range.getMzRange();
    Range<Integer> scanRange = range.getScanRange();

    if (msLevel == null) {
      // add to the top level range set
      anyLvlSet.add(scanRange);
      // remove from all underlying sets
      for (Map.Entry<Integer, MsLevelRangeSet> lvlMapEntry : lvlMap.entrySet()) {
        MsLevelRangeSet msLevelRangeSet = lvlMapEntry.getValue();
        msLevelRangeSet.removeFromAll(range);
      }
      return;
    }

    TreeRangeSet<Integer> scanRangeLeft = TreeRangeSet.create();
    scanRangeLeft.removeAll(anyLvlSet);
    if (scanRangeLeft.isEmpty()) {
      return; // if there's nothing left in the scan range, just stop
    }

    MsLevelRangeSet msLvlRanges = lvlMap.get(msLevel);
    if (msLvlRanges == null) {
      msLvlRanges = new MsLevelRangeSet();
      lvlMap.put(msLevel, msLvlRanges);
    }
    if (mzRange == null) {
      // add to any-mz-range range set
      msLvlRanges.anyPrecursorSet.addAll(scanRangeLeft);
      // remove from all specific mz-range sets
      msLvlRanges.removeFromSpecific(range);
      return;
    }

    scanRangeLeft.removeAll(msLvlRanges.anyPrecursorSet);
    if (scanRangeLeft.isEmpty()) {
      return;
    }

    RangeSet<Integer> rangeSetForMzRange = msLvlRanges.rngMap.get(mzRange);
    if (rangeSetForMzRange == null) {
      rangeSetForMzRange = TreeRangeSet.create();
      msLvlRanges.rngMap.put(mzRange, rangeSetForMzRange);
    }
    rangeSetForMzRange.addAll(scanRangeLeft);
  }
983311
public Query range(ByteStringRange range) {
    RowRange.Builder rangeBuilder = RowRange.newBuilder();

    switch (range.getStartBound()) {
      case OPEN:
        rangeBuilder.setStartKeyOpen(range.getStart());
        break;
      case CLOSED:
        rangeBuilder.setStartKeyClosed(range.getStart());
        break;
      case UNBOUNDED:
        rangeBuilder.clearStartKey();
        break;
      default:
        throw new IllegalStateException("Unknown start bound: " + range.getStartBound());
    }

    switch (range.getEndBound()) {
      case OPEN:
        rangeBuilder.setEndKeyOpen(range.getEnd());
        break;
      case CLOSED:
        rangeBuilder.setEndKeyClosed(range.getEnd());
        break;
      case UNBOUNDED:
        rangeBuilder.clearEndKey();
        break;
      default:
        throw new IllegalStateException("Unknown end bound: " + range.getEndBound());
    }

    builder.getRowsBuilder().addRowRanges(rangeBuilder.build());

    return this;
  }
714767
public static Protos.Resource ports(Protos.Value.Range... ranges) {
		return ports(UNRESERVED_ROLE, ranges);
	}
965346
public Range intersect(final Range outerRange) throws RangeException {
		if (min > outerRange.max) {
			throw new IllegalArgumentException("range maximum must be greater or equal than " + min);
		}
		if (max < outerRange.min) {
			throw new IllegalArgumentException("range minimum must be less or equal than " + max);
		}
		int newMin = Math.max(min, outerRange.min);
		int newMax = Math.min(max, outerRange.max);
		return new Range(newMin, newMax);
	}
334474
public TextRange newRange(int startOffset, int endOffset) {
    checkMetadata();
    return newRangeValidPointers(newPointer(startOffset), newPointer(endOffset), false);
  }
896089
func NewRanges(ranges ...Range) Ranges {
	var result Ranges
	for _, r := range ranges {
		result = result.AddRange(r)
	}
	return result
}
788251
public static RangeSet split(Collection<RangeSet> rangeSets)
    {
        RangeSet result = new RangeSet();
        SortedSet<Integer> ss = new TreeSet<Integer>();
        for (RangeSet rs : rangeSets)
        {
            for (CharRange r : rs)
            {
                ss.add(r.getFrom());
                ss.add(r.getTo());
            }
        }
        Iterator<Integer> i = ss.iterator();
        if (i.hasNext())
        {
            int from = i.next();
            while (i.hasNext())
            {
                int to = i.next();
                if (from != to)
                {
                    for (RangeSet rs : rangeSets)
                    {
                        if (rs.contains(from, to))
                        {
                            result.add(from, to);
                            break;
                        }
                    }
                }
                from = to;
            }
        }
        return result;
    }
906777
public static RangeSet merge(RangeSet rs)
    {
        RangeSet result = new RangeSet();
        int from = -1;
        int to = -1;
        for (CharRange r : rs)
        {
            if (from == -1) // first
            {
                from = r.getFrom();
                to = r.getTo();
            }
            else
            {
                if (r.getFrom() == to)
                {
                    to = r.getTo();
                }
                else
                {
                    result.add(from, to);
                    from = r.getFrom();
                    to = r.getTo();
                }
            }
        }
        result.add(from, to);
        return result;
    }
197917
public static int count(final Iterable<Range<Long>> ranges) {
        int count = 0;
        for (Range<Long> range : ranges) {
            checkClosedOpen(range);
            count++;
        }
        return count;
    }
112423
function(nodeOptions) {
      var ranges = this.getOwnRanges(),
          node, nodes = [];
      if (ranges.length == 0) {
        return nodes;
      }

      for (var i = ranges.length; i--;) {
        node = this.doc.createElement(nodeOptions.nodeName);
        nodes.push(node);
        if (nodeOptions.className) {
          node.className = nodeOptions.className;
        }
        if (nodeOptions.cssStyle) {
          node.setAttribute('style', nodeOptions.cssStyle);
        }
        try {
          // This only works when the range boundaries are not overlapping other elements
          ranges[i].surroundContents(node);
          this.selectNode(node);
        } catch(e) {
          // fallback
          node.appendChild(ranges[i].extractContents());
          ranges[i].insertNode(node);
        }
      }
      return nodes;
    }
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;
    }
999725
static SortedRangeSet copyOf(Type type, Iterable<Range> ranges)
    {
        return new Builder(type).addAll(ranges).build();
    }
1107237
public static List expand(String ranges, int maxNumber) {
        SequenceList parse = new SequenceList(ranges);
        LinkedList list = new LinkedList();
        boolean sair = false;
        while (!sair) {
            sair = parse.getAttributes();
            if (parse.low == -1 && parse.high == -1 && !parse.even && !parse.odd)
                continue;
            if (parse.low < 1)
                parse.low = 1;
            if (parse.high < 1 || parse.high > maxNumber)
                parse.high = maxNumber;
            if (parse.low > maxNumber)
                parse.low = maxNumber;
            
            //System.out.println("low="+parse.low+",high="+parse.high+",odd="+parse.odd+",even="+parse.even+",inverse="+parse.inverse);
            int inc = 1;
            if (parse.inverse) {
                if (parse.low > parse.high) {
                    int t = parse.low;
                    parse.low = parse.high;
                    parse.high = t;
                }
                for (ListIterator it = list.listIterator(); it.hasNext();) {
                    int n = ((Integer)it.next()).intValue();
                    if (parse.even && (n & 1) == 1)
                        continue;
                    if (parse.odd && (n & 1) == 0)
                        continue;
                    if (n >= parse.low && n <= parse.high)
                        it.remove();
                }
            }
            else {
                if (parse.low > parse.high) {
                    inc = -1;
                    if (parse.odd || parse.even) {
                        --inc;
                        if (parse.even)
                            parse.low &= ~1;
                        else
                            parse.low -= ((parse.low & 1) == 1 ? 0 : 1);
                    }
                    for (int k = parse.low; k >= parse.high; k += inc)
                        list.add(Integer.valueOf(k));
                }
                else {
                    if (parse.odd || parse.even) {
                        ++inc;
                        if (parse.odd)
                            parse.low |= 1;
                        else
                            parse.low += ((parse.low & 1) == 1 ? 1 : 0);
                    }
                    for (int k = parse.low; k <= parse.high; k += inc) {
                        list.add(Integer.valueOf(k));
                    }
                }
            }
        }
        return list;
    }
496150
@Override
  public Collection<Range<T>> rangesContaining(final Range<T> queryRange) {
    final ImmutableSet.Builder<Range<T>> ret = ImmutableSet.builder();
    for (final Range<T> range : ranges) {
      if (range.encloses(queryRange)) {
        ret.add(range);
      }
    }
    return ret.build();
  }
893054
private function createRange($ranges)
    {
        $rangeOfString = '';
        foreach ($ranges as $range) {
           $rangeOfString .= implode('', range($range[0], $range[2]));
        }

        return $rangeOfString;
    }
86783
function createRange(el, selection) {

  var start = selection.start;
  var end = selection.end;

  var range = document.createRange();

  var i = iterator(el.firstChild, el);

  var next = i.node;
  var isClosing = false;

  var count = 0;
  var length;

  while (next) {

    if (count === start) {
      if (isClosing) {
        range.setStartAfter(next);
      } else {
        range.setStartBefore(next);
      }
    }

    if (count === end) {
      if (isClosing) {
        range.setEndAfter(next);
      } else {
        range.setEndBefore(next);
      }

      return range;
    }

    if (!isClosing) {
      if (
        isBr(next) || (
          next.previousSibling && (
            isDiv(next) ||
            isParagraph(next)
          )
        )
      ) {
        count++;
      }
    }

    if (isText(next)) {

      length = next.textContent.length;

      if (count <= start && count + length > start) {
        range.setStart(next, start - count);
      }

      if (count + length > end) {
        range.setEnd(next, end - count);

        return range;
      }

      count += length;
    }

    next = i.next();
    isClosing = i.closingTag;
  }

  // out of range
  if (count <= start) {
    if (el.lastChild) {
      range.setStartAfter(el.lastChild);
    } else {
      range.setStart(el, 0);
    }
  }

  if (el.lastChild) {
    range.setEndAfter(el.lastChild);
  } else {
    range.setEnd(el, 0);
  }

  return range;
}