Parses a single id range, eg "1" or "1:2" or "4:*".

@param range the range.
@return the parsed id range.
185161
public static IdRange parseRange(String range) {
        int pos = range.indexOf(':');
        try {
            if (pos == -1) {
                long value = parseLong(range);
                return new IdRange(value);
            } else {
                long lowVal = parseLong(range.substring(0, pos));
                long highVal = parseLong(range.substring(pos + 1));
                return new IdRange(lowVal, highVal);
            }
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Invalid message set " + range);
        }
    }
548295
private function extractRange($range)
    {
        if (\preg_match('/^\d+$/', $range)) {
            return [$range, $range + 1];
        }

        $matches = [];
        if ($range !== '..' && \preg_match('/^(\d*)\.\.(\d*)$/', $range, $matches)) {
            $start = $matches[1] ? \intval($matches[1]) : 0;
            $end   = $matches[2] ? \intval($matches[2]) + 1 : PHP_INT_MAX;

            return [$start, $end];
        }

        throw new \InvalidArgumentException('Unexpected range: ' . $range);
    }
84469
public static <N extends Number & Comparable<? super N>> Rectangle range(final Range<N> range) {
        checkNotNull(range);
        if (range.isEmpty()) {
            throw new IllegalArgumentException("range must not be empty");
        }
        if (!range.hasLowerBound() || !range.hasUpperBound()) {
            throw new IllegalArgumentException("range must have lower and upper bounds");
        }
        Number lowerEndpoint = range.lowerEndpoint();
        BoundType lowerBoundType = range.lowerBoundType();
        Number upperEndpoint = range.upperEndpoint();
        BoundType upperBoundType = range.upperBoundType();

        /*

          Since we are representing genomic coordinate systems, the expectation is
          that endpoints are instance of Integer, Long, or BigInteger; thus for open
          lower and upper bounds we can safely add or substract 1.0 respectively.

          Then by convention a rectangle with y1 0.0 and height of 1.0 is used.

          closed(10, 20) --> (10.0, 0.0, 20.0, 1.0)
          closedOpen(10, 20) --> (10.0, 0.0, 19.0, 1.0)
          openClosed(10, 20) --> (11.0, 0.0, 20.0, 1.0)
          open(10, 20) --> (11.0, 0.0, 19.0, 1.0);

          closed(10, 11) --> (10.0, 0.0, 11.0, 1.0)
          closedOpen(10, 11) --> (10.0, 0.0, 10.0, 1.0)
          openClosed(10, 11) --> (11.0, 0.0, 11.0, 1.0)
          open(10, 11) --> empty, throw exception

          closed(10, 10) --> (10.0, 0.0, 10.0, 1.0)
          closedOpen(10, 10) --> empty, throw exception
          openClosed(10, 10) --> empty, throw exception
          open(10, 10) --> empty, throw exception

        */
        double x1 = lowerBoundType == BoundType.OPEN ? lowerEndpoint.doubleValue() + 1.0d : lowerEndpoint.doubleValue();
        double y1 = 0.0d;
        double x2 = upperBoundType == BoundType.OPEN ? upperEndpoint.doubleValue() - 1.0d : upperEndpoint.doubleValue();
        double y2 = 1.0d;
        return Geometries.rectangle(x1, y1, x2, y2);
    }
201317
public List<InetAddress> getEndpoint(Range<Token> range)
    {
        return (List<InetAddress>) rangeMap.get(range);
    }
638822
public IntegerRanges getRange(String name) {
    String valueString = get(name);
    Preconditions.checkNotNull(valueString);
    return new IntegerRanges(valueString);
  }
344693
protected static String parseValue (String line)
    {
        int eidx = line.indexOf("=");
        return (eidx == -1) ? "" : line.substring(eidx+1).trim();
    }
36869
public Range convertToSeq1Range(Range rangeInSeq2) {
        int from = aabs(convertToSeq1Position(rangeInSeq2.getFrom()));
        int to = aabs(convertToSeq1Position(rangeInSeq2.getTo()));

        if (from == -1 || to == -1)
            return null;

        return new Range(from, to);
    }
880483
public boolean IsOverlapping(DoubleRange range) {
        return ((isInside(range.min)) || (isInside(range.max)) ||
                (range.isInside(min)) || (range.isInside(max)));
    }
759958
public Range<App> listApps(String range) {
        return connection.execute(new AppList(range), apiKey);
    }
219250
protected RangeToken parseSetOperations() throws ParseException {
		RangeToken tok = this.parseCharacterClass(false);
		int type;
		while ((type = this.read()) != T_RPAREN) {
			int ch = this.chardata;
			if (type == T_CHAR && (ch == '-' || ch == '&') || type == T_PLUS) {
				this.next();
				if (this.read() != T_LBRACKET)
					throw ex("parser.ope.1", this.offset - 1);
				RangeToken t2 = this.parseCharacterClass(false);
				if (type == T_PLUS)
					tok.mergeRanges(t2);
				else if (ch == '-')
					tok.subtractRanges(t2);
				else if (ch == '&')
					tok.intersectRanges(t2);
				else
					throw new RuntimeException("ASSERT");
			} else {
				throw ex("parser.ope.2", this.offset - 1);
			}
		}
		this.next();
		return tok;
	}
1017020
public static long length(final Range<Long> range) {
        checkClosedOpen(range);
        return Math.max(0L, range.upperEndpoint() - range.lowerEndpoint());
    }
877760
@SuppressWarnings("unchecked")
    public static List<Integer> getAt(int[] array, ObjectRange range) {
        return primitiveArrayGet(array, range);
    }
367583
def parse_range_header(range):
    '''
    
    '''
    match = re.match('^items=([0-9]+)-([0-9]+)$', range)
    if match:
        start = int(match.group(1))
        finish = int(match.group(2))
        if finish < start:
            finish = start
        return {
            'start': start,
            'finish': finish,
            'number': finish - start + 1
        }
    else:
        return False
781989
public static long[][] parseRanges(String rangeValue) {
		if (!rangeValue.startsWith("bytes=")) return null;
		int s = "bytes=".length();
		int pcomma = rangeValue.indexOf(',', s);
		if (pcomma < 0) {
			long[] range = parseRange(rangeValue.substring(s));
			return range != null ? new long[][] { range } : null;
		}
		int e = rangeValue.length();
		List<long[]> ranges = new ArrayList<long[]>();
		while (true) {
			long[] range = parseRange(rangeValue.substring(s, pcomma));
			// TODO: too strict? fails on double comma.
			if (range == null) return null;
			ranges.add(range);
			if ((s = pcomma + 1) >= e) break;
			pcomma = rangeValue.indexOf(',', s);
			if (pcomma < 0) pcomma = e;
		}
		return ranges.toArray(new long[ranges.size()][]);
	}
639824
private Hashable find(Range<Token> range)
    {
        try
        {
            return findHelper(root, new Range<Token>(fullRange.left, fullRange.right), range);
        }
        catch (StopRecursion e)
        {
            return new Leaf();
        }
    }
222594
public static <T extends Identifier> List<T> parseList(final String ids, final IdentifierFactory factory) {
    final List<T> result = new ArrayList<>();
    for (final String token : ids.split(DELIMITER)) {
      result.add((T) factory.getNewInstance(token.trim()));
    }
    return result;
  }
466249
protected ArrayList<Range> parseRange(final HttpServletRequest request, final HttpServletResponse response, final Attributes resourceAttributes)
			throws IOException {

		// Checking If-Range
		final String headerValue = request.getHeader("If-Range");

		if (headerValue != null) {

			long headerValueTime = (-1L);
			try {
				headerValueTime = request.getDateHeader("If-Range");
			} catch (final IllegalArgumentException e) {
				// Ignore
			}

			final String eTag = resourceAttributes.getETag();
			final long lastModified = resourceAttributes.getLastModified();

			if (headerValueTime == (-1L)) {

				// If the ETag the client gave does not match the entity
				// etag, then the entire entity is returned.
				if (!eTag.equals(headerValue.trim()))
					return FULL;

			} else {

				// If the timestamp of the entity the client got is older than
				// the last modification date of the entity, the entire entity
				// is returned.
				if (lastModified > (headerValueTime + 1000))
					return FULL;

			}

		}

		final long fileLength = resourceAttributes.getContentLength();

		if (fileLength == 0)
			return null;

		// Retrieving the range header (if any is specified
		String rangeHeader = request.getHeader("Range");

		if (rangeHeader == null)
			return null;
		// bytes is the only range unit supported (and I don't see the point
		// of adding new ones).
		if (!rangeHeader.startsWith("bytes")) {
			response.addHeader("Content-Range", "bytes */" + fileLength);
			response.sendError(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
			return null;
		}

		rangeHeader = rangeHeader.substring(6);

		// Vector which will contain all the ranges which are successfully
		// parsed.
		final ArrayList<Range> result = new ArrayList<Range>();
		final StringTokenizer commaTokenizer = new StringTokenizer(rangeHeader, ",");

		// Parsing the range list
		while (commaTokenizer.hasMoreTokens()) {
			final String rangeDefinition = commaTokenizer.nextToken().trim();

			final Range currentRange = new Range();
			currentRange.length = fileLength;

			final int dashPos = rangeDefinition.indexOf('-');

			if (dashPos == -1) {
				response.addHeader("Content-Range", "bytes */" + fileLength);
				response.sendError(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
				return null;
			}

			if (dashPos == 0) {

				try {
					final long offset = Long.parseLong(rangeDefinition);
					currentRange.start = fileLength + offset;
					currentRange.end = fileLength - 1;
				} catch (final NumberFormatException e) {
					response.addHeader("Content-Range", "bytes */" + fileLength);
					response.sendError(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
					return null;
				}

			} else {

				try {
					currentRange.start = Long.parseLong(rangeDefinition.substring(0, dashPos));
					if (dashPos < rangeDefinition.length() - 1)
						currentRange.end = Long.parseLong(rangeDefinition.substring(dashPos + 1, rangeDefinition.length()));
					else
						currentRange.end = fileLength - 1;
				} catch (final NumberFormatException e) {
					response.addHeader("Content-Range", "bytes */" + fileLength);
					response.sendError(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
					return null;
				}

			}

			if (!currentRange.validate()) {
				response.addHeader("Content-Range", "bytes */" + fileLength);
				response.sendError(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
				return null;
			}

			result.add(currentRange);
		}

		return result;
	}