private Pair<Integer, Integer> minHammingDistance(String s, String[] choices, int len) { int min = Integer.MAX_VALUE; int minIndex = -1; for (int i = 0; i < len; i++) { int dist = hammingDistance(s, choices[i]); if (dist < min) { min = dist; minIndex = i; } } return new Pair<>(minIndex, min); } }
private static List<Pair<String, PreToken>> pretokenizeName(String name) { List<Pair<String, PreToken>> pattern = new ArrayList<>(); char c = name.charAt(0); PreToken currPT = PreToken.charToPreToken(c); StringBuffer curr = new StringBuffer(); curr.append(c); for (int i = 1; i < name.length(); i++) { c = name.charAt(i); PreToken newPT = PreToken.charToPreToken(c); if (newPT != currPT) { pattern.add(new Pair<>(new String(curr), currPT)); curr = new StringBuffer(); currPT = newPT; } curr.append(c); } pattern.add(new Pair<>(new String(curr), currPT)); return pattern; }
private Pair<Integer, Double> findBestRegex(final List<List<String>> candidates) { // choose the candidate role regex with the maximal "role score" return IntStream.range(0, candidates.size()) .mapToObj(i -> new Pair<>(i, computeRoleScore(regexTokensToRegex(candidates.get(i))))) .max(Comparator.comparingDouble(Pair::getSecond)) .orElseThrow(() -> new BatfishException("this exception should not be reachable")); }
public TransferResult<U, T> addChangedVariable(String s, Expr x) { TransferResult<U, T> ret = new TransferResult<>(this); ret._changedVariables = ret._changedVariables.plus(new Pair<>(s, x)); return ret; }
private static List<Pair<String, Token>> preTokensToUndelimitedTokens( List<Pair<String, PreToken>> pretokens) { List<Pair<String, Token>> tokens = new ArrayList<>(); int size = pretokens.size(); for (int i = 0; i < size; i++) { String chars = pretokens.get(i).getFirst(); PreToken pt = pretokens.get(i).getSecond(); switch (pt) { case ALPHA_PLUS: int next = i + 1; if (next >= size) { tokens.add(new Pair<>(chars, Token.ALPHA_PLUS)); } else { // the next token must be DIGIT_PLUS since we know there are no delimiters String bothChars = chars + pretokens.get(next).getFirst(); tokens.add(new Pair<>(bothChars, Token.ALPHA_PLUS_DIGIT_PLUS)); i++; } break; case DIGIT_PLUS: tokens.add(new Pair<>(chars, Token.DIGIT_PLUS)); break; default: throw new BatfishException("Unexpected pretoken " + pt); } } return tokens; }
descs.put( ADD_ANALYSIS_QUESTIONS, new Pair<>( "<analysis-name> <question-directory>", "Add questions from the directory to the analysis")); descs.put( ADD_BATFISH_OPTION, new Pair<>( "<option-key> [<option-value> [<option-value>] ... ]", "Additional options to pass to Batfish")); descs.put( ANSWER, new Pair<>( "<template-name> [differential={true,false}] [questionName=name] [param1=value1 [param2=value2] ...]", "Answer the template by name for the current snapshot")); descs.put( ANSWER_REFERENCE, new Pair<>( "<template-name> [differential={true,false}] [questionName=name] [param1=value1 [param2=value2] ...]", "Answer the template by name for the reference snapshot")); descs.put( AUTOCOMPLETE, new Pair<>( "[-maxSuggestions] <completion-type> <query>", "Autocomplete information of question parameters")); descs.put(CAT, new Pair<>("<filename>", "Print the contents of the file")); descs.put(CHECK_API_KEY, new Pair<>("", "Check if API Key is valid")); descs.put(CLEAR_SCREEN, new Pair<>("", "Clear screen")); descs.put(
private static List<Pair<String, Token>> preTokensToDelimitedTokens( List<Pair<String, PreToken>> pretokens) { List<Pair<String, Token>> tokens = new ArrayList<>(); int size = pretokens.size(); for (int i = 0; i < size; i++) { StringBuilder chars = new StringBuilder(pretokens.get(i).getFirst()); PreToken pt = pretokens.get(i).getSecond(); switch (pt) { case ALPHA_PLUS: // combine everything up to the next delimiter into a single alphanumeric token int next = i + 1; while (next < size && pretokens.get(next).getSecond() != PreToken.DELIMITER) { chars.append(pretokens.get(next).getFirst()); next++; } i = next - 1; tokens.add(new Pair<>(chars.toString(), Token.ALNUM_PLUS)); break; case DELIMITER: tokens.add(new Pair<>(chars.toString(), Token.DELIMITER)); break; case DIGIT_PLUS: tokens.add(new Pair<>(chars.toString(), Token.DIGIT_PLUS)); break; default: throw new BatfishException("Unknown pretoken " + pt); } } return tokens; }
public PList<Pair<String, Pair<Expr, Expr>>> mergeChangedVariables(TransferResult<U, T> other) { Set<String> seen = new HashSet<>(); PList<Pair<String, Pair<Expr, Expr>>> vars = PList.empty(); for (Pair<String, Expr> cv1 : this._changedVariables) { String s = cv1.getFirst(); Expr x = cv1.getSecond(); if (!seen.contains(s)) { seen.add(s); Expr e = find(other._changedVariables, s); Pair<Expr, Expr> pair = new Pair<>(x, e); vars = vars.plus(new Pair<>(s, pair)); } } for (Pair<String, Expr> cv1 : other._changedVariables) { String s = cv1.getFirst(); Expr x = cv1.getSecond(); if (!seen.contains(s)) { seen.add(s); Expr e = find(this._changedVariables, s); Pair<Expr, Expr> pair = new Pair<>(e, x); // preserve order vars = vars.plus(new Pair<>(s, pair)); } } return vars; }
public synchronized Pair<InterfaceAddress, InterfaceAddress> getNextGeneratedLinkSubnet() { assert _currentGeneratedIpAsLong % 2 == 0; InterfaceAddress val = new InterfaceAddress(Ip.create(_currentGeneratedIpAsLong), Prefix.MAX_PREFIX_LENGTH - 1); InterfaceAddress val2 = new InterfaceAddress( Ip.create(_currentGeneratedIpAsLong + 1), Prefix.MAX_PREFIX_LENGTH - 1); _currentGeneratedIpAsLong += 2L; return new Pair<>(val, val2); }
Pair<InterfaceAddress, Integer> key = new Pair<>(address, groupNum); Set<Interface> candidates = vrrpGroups.computeIfAbsent(
String router = ge.getRouter(); Ip ip = n.getLocalIp(); Pair<String, Ip> pair = new Pair<>(router, ip);
Prefix pfx = sr.getNetwork(); Integer adminCost = sr.getAdministrativeCost(); Pair<Prefix, Integer> tup = new Pair<>(pfx, adminCost); staticPrefixes.add(tup);
Pair<Ip, Ip> localKey = new Pair<>(localIp, remoteIp); RipNeighbor neighbor = proc.getRipNeighbors().get(localKey); if (neighbor == null) { Pair<Ip, Ip> remoteKey = new Pair<>(remoteIp, localIp); RipNeighbor remoteNeighbor = new RipNeighbor(remoteKey); remoteNeighbor.setVrf(remoteVrfName); Pair<Ip, Ip> key = new Pair<>(localIp, Ip.ZERO); RipNeighbor neighbor = new RipNeighbor(key); neighbor.setVrf(vrfName);
@Nullable Pair<WorkStatusCode, String> getWorkStatus(UUID workId) { try { WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_GET_WORKSTATUS); MultiPart multiPart = new MultiPart(); multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE); addTextMultiPart(multiPart, CoordConsts.SVC_KEY_API_KEY, _settings.getApiKey()); addTextMultiPart(multiPart, CoordConsts.SVC_KEY_WORKID, workId.toString()); JSONObject jObj = postData(webTarget, multiPart); if (jObj == null) { return null; } if (!jObj.has(CoordConsts.SVC_KEY_WORKSTATUS)) { _logger.errorf("workstatus key not found in: %s\n", jObj); return null; } WorkStatusCode workStatus = WorkStatusCode.valueOf(jObj.getString(CoordConsts.SVC_KEY_WORKSTATUS)); if (!jObj.has(CoordConsts.SVC_KEY_TASKSTATUS)) { _logger.errorf("taskstatus key not found in: %s\n", jObj); } String taskStr = jObj.getString(CoordConsts.SVC_KEY_TASKSTATUS); return new Pair<>(workStatus, taskStr); } catch (Exception e) { _logger.errorf("exception: "); _logger.error(Throwables.getStackTraceAsString(e) + "\n"); return null; } }
@Test public void testCompareTo() { Ip ip1 = Ip.parse("1.1.1.1"); Ip ip2 = Ip.parse("2.2.2.2"); Pair<Ip, Ip> ipPair1 = new Pair<>(ip1, ip1); Pair<Ip, Ip> ipPair2 = new Pair<>(ip2, ip2); String node1 = "node1"; String node2 = "node2"; IpEdge ipEdge1 = new IpEdge(node1, ip1, node1, ip1); IpEdge ipEdge2 = new IpEdge(node2, ip2, node2, ip2); RipNeighbor neighbor1 = new RipNeighbor(ipPair1); RipNeighbor neighbor2 = new RipNeighbor(ipPair2); VerboseRipEdge ripEdge1 = new VerboseRipEdge(neighbor1, neighbor1, ipEdge1); VerboseRipEdge ripEdge1Copy = new VerboseRipEdge(neighbor1, neighbor1, ipEdge1); VerboseRipEdge ripEdge2 = new VerboseRipEdge(neighbor2, neighbor2, ipEdge2); assertThat(ripEdge1.compareTo(ripEdge1Copy), is(0)); assertThat(ripEdge1.compareTo(ripEdge2), lessThan(0)); assertThat(ripEdge2.compareTo(ripEdge1), greaterThan(0)); } }
r.getReturnAssignedValue(), variable, _enc.mkIf(guard, (BoolExpr) t, (BoolExpr) f)); BoolExpr ret = createBoolVariableWith(p, variableName, newValue); return new Pair<>(ret, retAss); ArithExpr ret = createArithVariableWith(p, "PREFIX-LEN", newValue); p.getData().setPrefixLength(ret); return new Pair<>(ret, null); ArithExpr ret = createArithVariableWith(p, "ADMIN-DIST", newValue); p.getData().setAdminDist(ret); return new Pair<>(ret, null); ArithExpr ret = createArithVariableWith(p, "LOCAL-PREF", newValue); p.getData().setLocalPref(ret); return new Pair<>(ret, null); ArithExpr ret = createArithVariableWith(p, "METRIC", newValue); p.getData().setMetric(ret); return new Pair<>(ret, null); BitVecExpr ret = createBitVecVariableWith(p, "OSPF-TYPE", 2, newValue); p.getData().getOspfType().setBitVec(ret); return new Pair<>(ret, null); BoolExpr ret = createBoolVariableWith(p, cvar.getValue(), newValue); p.getData().getCommunities().put(cvar, ret); return new Pair<>(ret, null);
RipProcess rip2 = new RipProcess(); RipNeighbor ripNeighbor1 = new RipNeighbor(new Pair<>(Ip.parse("1.1.1.1"), Ip.parse("2.2.2.2"))); RipNeighbor ripNeighbor2 = new RipNeighbor(new Pair<>(Ip.parse("2.2.2.2"), Ip.parse("1.1.1.1"))); rip1.setRipNeighbors( ImmutableSortedMap.of(new Pair<>(Ip.parse("1.1.1.1"), Ip.parse("2.2.2.2")), ripNeighbor1)); rip2.setRipNeighbors( ImmutableSortedMap.of(new Pair<>(Ip.parse("2.2.2.2"), Ip.parse("1.1.1.1")), ripNeighbor2)); ripNeighbor1.setOwner(_host1); ripNeighbor2.setOwner(_host2);