/*
(non-Javadoc)
@see net.ossindex.version.parser.VersionBaseListener#exitMaven_inclusive_range(net.ossindex.version.parser.VersionParser.Maven_inclusive_rangeContext)
19613
@Override
  public void exitMaven_range(VersionParser.Maven_rangeContext ctx) {

    // This could be a version set
    if (ctx.getChildCount() == 3) {
      VersionSet set = new VersionSet();
      if (!"-".equals(ctx.getChild(1).getText())) {
        SemanticVersion v1 = (SemanticVersion) stack.pop();
        set.add(v1);
      }
      stack.push(set);
      return;
    }

    // Possibly an empty set
    if (ctx.getChildCount() == 2) {
      VersionSet set = new VersionSet();
      stack.push(set);
      return;
    }

    // Otherwise it is a range. Load the tokens first.
    int index = 0;
    String open = ctx.getChild(index).getText();
    index++;
    SemanticVersion v1 = null;
    SemanticVersion v2 = null;
    String text = ctx.getChild(index).getText();
    if (!",".equals(text)) {
      v1 = (SemanticVersion) stack.pop();
      index++;
    }
    index++;
    String close = null;
    text = ctx.getChild(index).getText();
    if ("]".equals(text) || ")".equals(text)) {
      close = text;
    }
    else {
      v2 = (SemanticVersion) stack.pop();
      index++;
      close = ctx.getChild(index).getText();
    }

    // We need to swap the values, cause they are peeled of the stack in reverse order
    if (v1 != null && v2 != null) {
      SemanticVersion tmp = v1;
      v1 = v2;
      v2 = tmp;
    }

    // Figure out what the range endpoints are
    IVersionRange r1 = null;
    if (v1 != null) {
      switch (open) {
        case "(":
          r1 = new VersionRange(">", v1);
          break;
        case "[":
          r1 = new VersionRange(">=", v1);
          break;
      }
    }

    IVersionRange r2 = null;
    if (v2 != null) {
      switch (close) {
        case ")":
          r2 = new VersionRange("<", v2);
          break;
        case "]":
          r2 = new VersionRange("<=", v2);
          break;
      }
    }

    // Now assemble the range
    if (r1 != null) {
      if (r2 != null) {
        IVersionRange andRange = new AndRange(r1, r2);
        andRange.setType("maven");
        stack.push(andRange);
      }
      else {
        stack.push(r1);
        r1.setType("maven");
      }
    }
    else {
      stack.push(r2);
      r2.setType("maven");
    }
  }
533530
function invalidRange(res) {
  var body = 'Requested Range Not Satisfiable';
  res.setHeader('Content-Type', 'text/plain');
  res.setHeader('Content-Length', body.length);
  res.statusCode = 416;
  res.end(body);
}
743514
@Override
    public void removeRange(int fromIndex, int toIndex) {
        if (fromIndex > toIndex) {
            throw new IllegalArgumentException("fromIndex must be <= toIndex");
        }
        for (int i = toIndex; i >= fromIndex; i--) {
            removeElementAt(i);
        }
        fireIntervalRemoved(this, fromIndex, toIndex);
    }
1122200
@Override
    public void contextDestroyed(ServletContextEvent event) {
        try {
            _gate.await();
            _logger.info("Stopping Argus web services.");
            _system.getServiceFactory().getMonitorService().stopRecordingCounters();
            _system.getServiceFactory().getSchedulingService().stopAlertScheduling();
            _system.getServiceFactory().getWardenService().disableWarden();
            _system.stop();
        } catch (InterruptedException ex) {
            _logger.info("Interrupted while waiting for startup to complete.");
        }
    }
512552
protected void removeExpired(Map<Integer, Context> contexts) {
        Iterator<Context> contextsIter = contexts.values().iterator();
        while (contextsIter.hasNext()) {
            Context context = contextsIter.next();
            if (context.completeMoment != null
                    && System.currentTimeMillis() - context.completeMoment > contextTimeout) {
                contextsIter.remove();
            }
        }
    }
433524
@Deprecated
  public void remove(final int rangeStart, final int rangeEnd) {
    if (rangeStart >= 0) {
      remove((long) rangeStart, (long) rangeEnd);
    }
    // rangeStart being -ve and rangeEnd being positive is not expected)
    // so assume both -ve
    remove(rangeStart & 0xFFFFFFFFL, rangeEnd & 0xFFFFFFFFL);
  }
1061086
def validate_version_range(version_range)
      SemanticPuppet::VersionRange.parse(version_range)
    rescue ArgumentError => e
      raise ArgumentError, _("Invalid 'version_range' field in metadata.json: %{err}") % { err: e }
    end
87963
public ProcessExecutor exitValue(Integer exitValue) {
    return exitValues(exitValue == null ? null : new Integer[] { exitValue } );
  }
199454
public boolean isSatisfiedBy(Semver version) {
        if (this.range != null) {
            // We are on a leaf
            return this.range.isSatisfiedBy(version);
        } else {
            // We have several sub-requirements
            switch (this.op) {
                case AND:
                    try {
                        List<Range> set = getAllRanges(this, new ArrayList<Range>());
                        for (Range range : set) {
                            if (!range.isSatisfiedBy(version)) {
                                return false;
                            }
                        }
                        if (version.getSuffixTokens().length > 0) {
                            // Find the set of versions that are allowed to have prereleases
                            // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
                            // That should allow `1.2.3-pr.2` to pass.
                            // However, `1.2.4-alpha.notready` should NOT be allowed,
                            // even though it's within the range set by the comparators.
                            for (Range range : set) {
                                if (range.version == null) {
                                    continue;
                                }
                                if (range.version.getSuffixTokens().length>0) {
                                    Semver allowed = range.version;
                                    if (Objects.equals(version.getMajor(), allowed.getMajor()) &&
                                            Objects.equals(version.getMinor(), allowed.getMinor()) &&
                                            Objects.equals(version.getPatch(), allowed.getPatch())) {
                                        return true;
                                    }
                                }
                            }
                            // Version has a -pre, but it's not one of the ones we like.
                            return false;
                        }
                        return true;
                    } catch (Exception e) {
                        // Could be that we have a OR in AND - fallback to default test
                        return this.req1.isSatisfiedBy(version) && this.req2.isSatisfiedBy(version);
                    }
                case OR:
                    return this.req1.isSatisfiedBy(version) || this.req2.isSatisfiedBy(version);
            }
            throw new RuntimeException("Code error. Unknown RequirementOperator: " + this.op); // Should never happen
        }
    }
1222005
@Override
  public void exitStandardEnumValueOptionDeprecated(
      final StandardEnumValueOptionDeprecatedContext ctx) {
    verifyOptionNameUnique("deprecated", ctx.getStart());
    scopes.getEnumValueOptions().setDeprecated(Boolean.valueOf(ctx.BooleanLiteral().getText()));
  }
361720
StatementDMQL compileDeleteStatement(RangeVariable[] outerRanges) {

        Expression condition       = null;
        boolean    truncate        = false;
        boolean    restartIdentity = false;

        switch (token.tokenType) {

            case Tokens.TRUNCATE : {
                read();
                readThis(Tokens.TABLE);

                truncate = true;

                break;
            }
            case Tokens.DELETE : {
                read();
                readThis(Tokens.FROM);

                break;
            }
        }

        RangeVariable[] rangeVariables = {
            readSimpleRangeVariable(StatementTypes.DELETE_WHERE) };
        Table table     = rangeVariables[0].getTable();
        Table baseTable = table.getBaseTable();

        /* A VoltDB Extension.
         * Views from Streams are now updatable.
         * Comment out this guard and check if it is a view
         * from Stream or PersistentTable in planner.
        if (!table.isUpdatable()) {
            throw Error.error(ErrorCode.X_42000);
        }
        A VoltDB Extension */

        if (truncate) {
            switch (token.tokenType) {

                case Tokens.CONTINUE : {
                    read();
                    readThis(Tokens.IDENTITY);

                    break;
                }
                case Tokens.RESTART : {
                    read();
                    readThis(Tokens.IDENTITY);

                    restartIdentity = true;

                    break;
                }
            }

            for (int i = 0; i < table.constraintList.length; i++) {
                if (table.constraintList[i].getConstraintType()
                        == Constraint.MAIN) {
                    throw Error.error(ErrorCode.X_23501);
                }
            }
        }

        if (truncate && table != baseTable) {
            throw Error.error(ErrorCode.X_42000);
        }

        if (!truncate && token.tokenType == Tokens.WHERE) {
            read();

            condition = XreadBooleanValueExpression();

            HsqlList unresolved =
                condition.resolveColumnReferences(outerRanges, null);

            unresolved = Expression.resolveColumnSet(rangeVariables,
                    unresolved, null);

            ExpressionColumn.checkColumnsResolved(unresolved);
            condition.resolveTypes(session, null);

            if (condition.isParam()) {
                condition.dataType = Type.SQL_BOOLEAN;
            }

            if (condition.getDataType() != Type.SQL_BOOLEAN) {
                throw Error.error(ErrorCode.X_42568);
            }
        }

        // VoltDB Extension:
        // baseTable could be null for stream views.
        if (baseTable != null && table != baseTable) {
            QuerySpecification select =
                ((TableDerived) table).getQueryExpression().getMainSelect();

            if (condition != null) {
                condition =
                    condition.replaceColumnReferences(rangeVariables[0],
                                                      select.exprColumns);
            }

            rangeVariables[0] = new RangeVariable(select.rangeVariables[0]);
            condition = ExpressionLogical.andExpressions(select.queryCondition,
                    condition);
        }

        if (condition != null) {
            RangeVariableResolver resolver =
                new RangeVariableResolver(rangeVariables, condition,
                                          compileContext);

            resolver.processConditions();

            rangeVariables = resolver.rangeVariables;
        }

        // VoltDB Extension:
        // This needs to be done before building the compiled statement
        // so that parameters in LIMIT or OFFSET are retrieved from
        // the compileContext
        SortAndSlice sas = voltGetSortAndSliceForDelete(rangeVariables);

        StatementDMQL cs = new StatementDML(session, table, rangeVariables,
                                            compileContext, restartIdentity);

        // VoltDB Extension:
        voltAppendDeleteSortAndSlice((StatementDML)cs, sas);

        return cs;
    }
1282211
@Override
  public void exitSemantic_range(VersionParser.Semantic_rangeContext ctx) {
    String operator = ctx.getChild(0).getText();
    Object o = stack.pop();
    if (o instanceof SemanticVersion) {
      switch (operator) {
        case "^":
          SemanticVersion sv = (SemanticVersion) o;
          VersionRange from = new VersionRange(">=", sv);
          VersionRange to = new VersionRange("<", sv.getNextCaretVersion());
          range = new AndRange(from, to);
          break;
      }
      stack.push(range);
    }
    else {
      throw new InvalidRangeRuntimeException("Expected a semantic version, got a " + o.getClass().getSimpleName());
    }
  }
1170742
@Override
  public void exitStandardMethodOptionDeprecated(final StandardMethodOptionDeprecatedContext ctx) {
    verifyOptionNameUnique("deprecated", ctx.getStart());
    scopes.getMethodOptions().setDeprecated(Boolean.valueOf(ctx.BooleanLiteral().getText()));
  }
669188
@Override
  public void exitStandardFileOptionJavaPackage(final StandardFileOptionJavaPackageContext ctx) {
    verifyOptionNameUnique("javaPackage", ctx.getStart());
    scopes.getFileOptions().setJavaPackage(removeQuotes(ctx.StringLiteral().getText()));
  }
846090
@Override
  public void exitIdentifier(VersionParser.IdentifierContext ctx) {
    String postfix = ctx.getText();
    // A numeric postfix cannot have leading zeroes
    // FIXME: Check to see if an alphanumeric postfix with leading zeroes counts
    Matcher m = numericHasLeadingZeroes.matcher(postfix);
    while (m.find()) {
      postfix = m.replaceAll("");
    }
    // Hack to ensure correct parsing by SemanticVersion code. A postfix MUST start with a dash, digit, or letter
    while (!postfix.isEmpty() && !startsWithDigitLetterOrHyphen.matcher(postfix).find()) {
      postfix = postfix.substring(1);
    }
    stack.push(postfix);
  }
1250288
private boolean isWithin(JavaVersion runningVersion, Range range,
			JavaVersion version) {
		if (range == Range.EQUAL_OR_NEWER) {
			return runningVersion.isEqualOrNewerThan(version);
		}
		if (range == Range.OLDER_THAN) {
			return runningVersion.isOlderThan(version);
		}
		throw new IllegalStateException("Unknown range " + range);
	}
67469
function resolveRangeBound(bound, opts, isStop, includeStop) {
  var result;
  if (isUndefined(bound)) {
    return isStop ? opts.maxLen : 0;
  }
  var useIntIndexing = (
    opts.resolveMode === RESOLVE_MODE.INT ||
    (opts.resolveMode === RESOLVE_MODE.COL && typeof bound === 'number')
  );
  if (includeStop === null) {
    includeStop = useIntIndexing ? false : true;
  }
  if (useIntIndexing) {
    result = resolveIntIdx(bound, opts.maxLen, false);
    return (isStop && includeStop) ? result + 1 : result;
  } else {
    if (opts.index.arity === 1) {
      result = opts.index.lookupKey([bound]);
      if (result === null) {
        throw new Error('could not find entry for range bound: ' + bound);
      } else if (typeof result === 'number') {
        return (isStop && includeStop) ? result + 1 : result;
      } else {
        return (isStop && includeStop) ?
          result[result.length - 1] + 1 :
          result[0];
      }
    } else {
      // TODO
      throw new Error('unimplemented case (TODO)');
    }
  }
}