List of usage examples for org.apache.commons.collections.keyvalue MultiKey MultiKey
public MultiKey(Object[] keys)
From source file:com.qq.tars.service.monitor.TARSPropertyMonitorService.java
private Set<MultiKey> mergeKey(TARSPropertyMonitorCondition condition, MultiKeyMap thedata, MultiKeyMap predata) {//from w w w .j a va2 s .c o m Set<MultiKey> keys = new TreeSet<>((left, right) -> { for (int i = 0; i < left.size(); i++) { Object leftKey = left.getKey(i); Object rightKey = right.getKey(i); if (leftKey.equals(rightKey)) { continue; } return ((String) leftKey).compareTo((String) rightKey); } return 0; }); keys.addAll(thedata.keySet()); for (Object obj : predata.keySet()) { Object[] keyparts = ((MultiKey) obj).getKeys(); if (keyparts.length > 1) { keyparts[0] = condition.getThedate(); } keys.add(new MultiKey(keyparts)); } return keys; }
From source file:com.qq.tars.service.monitor.TARSStatMonitorService.java
private Set<MultiKey> mergeKey(TARSStatMonitorCondition condition, MultiKeyMap thedata, MultiKeyMap predata) { Set<MultiKey> keys = new TreeSet<>((left, right) -> { for (int i = 0; i < left.size(); i++) { Object leftKey = left.getKey(i); Object rightKey = right.getKey(i); if (leftKey.equals(rightKey)) { continue; }//from www . j a v a2 s. c om return ((String) leftKey).compareTo((String) rightKey); } return 0; }); keys.addAll(thedata.keySet()); for (Object obj : predata.keySet()) { Object[] keyparts = ((MultiKey) obj).getKeys(); if (keyparts.length > 1) { keyparts[0] = condition.getThedate(); } keys.add(new MultiKey(keyparts)); } return keys; }
From source file:it.geosolutions.unredd.stats.impl.StatsRunner.java
protected void pivot(Map<MultiKey, List<Result>> results, int index, List<Double> pivotClasses) { // This map contains all results // - MultiKeys here are built by all the Keys in the original MultiKey except the pivotted one // - Key of the inner map is the class of the pivotted classification // - Value of the inner map is the result of the single stat requested Map<MultiKey, Map<Double, Double>> pivotted = new HashMap<MultiKey, Map<Double, Double>>(); // Regroup results by subkeys for (MultiKey classes : results.keySet()) { List<Result> result = results.get(classes); if (result.size() != 1) throw new IllegalStateException(); Double value = result.get(0).getValue(); // FIXME: this won't work with COUNT statistic // Create subKey (all keys except the pivot one) int newkeys = classes.getKeys().length - 1; Object subkeys[] = new Object[newkeys]; for (int i = 0; i < newkeys; i++) { subkeys[i] = classes.getKeys()[i + (i >= index ? 1 : 0)]; }/*ww w . j av a2 s . c o m*/ MultiKey subKey = new MultiKey(subkeys); Double pivotKey = ((Number) classes.getKeys()[index]).doubleValue(); Map<Double, Double> submap; if (pivotted.containsKey(subKey)) { submap = pivotted.get(subKey); } else { submap = new HashMap<Double, Double>(); pivotted.put(subKey, submap); } submap.put(pivotKey, value); } LOGGER.info("Pivotted " + pivotted.size() + " subkeys"); // build the output string for (MultiKey subKey : pivotted.keySet()) { StringBuilder sb = new StringBuilder(); // append classifications' classes for (Object object : subKey.getKeys()) { sb.append(object.toString()).append(cfg.getOutput().getSeparator()); } // append pivotted data Map<Double, Double> pvalues = pivotted.get(subKey); // export data in the requested order for (Iterator<Double> it = pivotClasses.iterator(); it.hasNext();) { Double pRequestedClass = it.next(); Double pval = pvalues.get(pRequestedClass); if (pval != null) sb.append(pval); else sb.append(cfg.getOutput().getMissingValue()); if (it.hasNext()) sb.append(cfg.getOutput().getSeparator()); } output(sb); } closeOutputFile(); }
From source file:com.qq.tars.service.monitor.TARSPropertyMonitorService.java
private MultiKeyMap call(List<String> groupBy, List<String> conditions) throws IOException { String template = "{\"groupby\":%s,\"method\":\"query\",\"dataid\":\"tars_property\"," + "\"filter\":%s,\"indexs\":[\"value\"]}"; ObjectMapper mapper = new ObjectMapper(); String request = String.format(template, mapper.writeValueAsString(groupBy), mapper.writeValueAsString(conditions)); List<Pair<String, Integer>> addrs = adminService.getEndpoints("tars.tarsqueryproperty.NoTarsObj"); if (addrs.isEmpty()) { throw new IOException("tars.tarsqueryproperty.NoTarsObj not found"); }/*from www . ja v a2 s. c o m*/ Pair<String, Integer> addr = addrs.get(0); log.info("tars.tarsqueryproperty.NoTarsObj, use {}:{}", addr.getLeft(), addr.getRight()); TCPClient client = new TCPClient(addr.getLeft(), addr.getRight()); List<String> response = client.sendAndReceive(request.getBytes(), 60000); log.debug("request={}", request); log.debug("reponse={}", StringUtils.join(response, "\n")); String line1 = response.get(0); if (!line1.startsWith("Ret:")) { throw new IOException(String.format("line #1, doesn't start with \"Ret:\", line=%s", line1)); } int ret = Integer.parseInt(line1.substring(line1.lastIndexOf(':') + 1)); if (ret == -1) { throw new IOException(String.format("line #1, Ret=%s", ret)); } String line6 = response.get(5); if (!line6.startsWith("linecount:")) { throw new IOException(String.format("line #6, doesn't start with \"linecount:\", line=%s", line6)); } int count = Integer.parseInt(line6.substring(line6.lastIndexOf(':') + 1)); if (count + 7 != response.size()) { throw new IOException(String.format("line #6, size not match, %s vs %s", count + 7, response.size())); } String lastLine = response.get(response.size() - 1); if (!"endline".equals(lastLine)) { throw new IOException( String.format("line #%s, doesn't equal to \"endline\", line=%s", response.size(), lastLine)); } MultiKeyMap result = new MultiKeyMap(); for (int i = 6; i < response.size() - 1; i++) { String line = StringUtils.removeEnd(response.get(i), ","); String[] tokens = line.split(","); if (tokens.length != groupBy.size() + 1) { throw new IOException(String.format("line format error, line=%s", line)); } String[] key = new String[groupBy.size()]; int j = 0; for (; j < key.length; j++) { key[j] = tokens[j]; } double[] value = new double[] { Double.parseDouble(tokens[j]) }; result.put(new MultiKey(key), value); } return result; }
From source file:com.qq.tars.service.monitor.TARSStatMonitorService.java
private MultiKeyMap call(List<String> groupBy, List<String> conditions) throws IOException { String template = "{\"groupby\":%s,\"method\":\"query\",\"dataid\":\"tars_stat\"," + "\"filter\":%s,\"indexs\":[\"succ_count\",\"timeout_count\",\"exce_count\",\"total_time\"]}"; ObjectMapper mapper = new ObjectMapper(); String request = String.format(template, mapper.writeValueAsString(groupBy), mapper.writeValueAsString(conditions)); List<Pair<String, Integer>> addrs = adminService.getEndpoints("tars.tarsquerystat.NoTarsObj"); if (addrs.isEmpty()) { throw new IOException("tars.tarsquerystat.NoTarsObj not found"); }/*from w w w. java2 s . c o m*/ Pair<String, Integer> addr = addrs.get(0); log.info("tars.tarsquerystat.NoTarsObj, use {}:{}", addr.getLeft(), addr.getRight()); TCPClient client = new TCPClient(addr.getLeft(), addr.getRight()); List<String> response = client.sendAndReceive(request.getBytes(), 60000); log.debug("request={}", request); log.debug("reponse={}", StringUtils.join(response, "\n")); String line1 = response.get(0); if (!line1.startsWith("Ret:")) { throw new IOException(String.format("line #1, doesn't start with \"Ret:\", line=%s", line1)); } int ret = Integer.parseInt(line1.substring(line1.lastIndexOf(':') + 1)); if (ret == -1) { throw new IOException(String.format("line #1, Ret=%s", ret)); } String line6 = response.get(5); if (!line6.startsWith("linecount:")) { throw new IOException(String.format("line #6, doesn't start with \"linecount:\", line=%s", line6)); } int count = Integer.parseInt(line6.substring(line6.lastIndexOf(':') + 1)); if (count + 7 != response.size()) { throw new IOException(String.format("line #6, size not match, %s vs %s", count + 7, response.size())); } String lastLine = response.get(response.size() - 1); if (!"endline".equals(lastLine)) { throw new IOException( String.format("line #%s, doesn't equal to \"endline\", line=%s", response.size(), lastLine)); } MultiKeyMap result = new MultiKeyMap(); for (int i = 6; i < response.size() - 1; i++) { String line = StringUtils.removeEnd(response.get(i), ","); String[] tokens = line.split(","); if (tokens.length != groupBy.size() + 4) { throw new IOException(String.format("line format error, line=%s", line)); } String[] key = new String[groupBy.size()]; int j = 0; for (; j < key.length; j++) { key[j] = tokens[j]; } long[] value = new long[] { Long.parseLong(tokens[j++]), Long.parseLong(tokens[j++]), Long.parseLong(tokens[j++]), Long.parseLong(tokens[j]) }; result.put(new MultiKey(key), value); } return result; }
From source file:org.kuali.student.common.util.spring.MethodArgsToObjectEhcacheAdvice.java
private MultiKey getCacheKey(ProceedingJoinPoint pjp) { List<Object> keyList = new ArrayList<Object>(); keyList.add(pjp.getSignature().getName()); for (Object arg : pjp.getArgs()) { if (arg == null) { keyList.add("_null_"); } else {//w w w .jav a 2 s . c o m keyList.add(arg.toString()); } } return new MultiKey(keyList.toArray()); }
From source file:org.kuali.student.enrollment.academicrecord.service.decorators.AcademicRecordServiceCachingDecorator.java
@Override public List<StudentCourseRecordInfo> getCompletedCourseRecords(String personId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { MultiKey cacheKey = new MultiKey(new String[] { personId }); @SuppressWarnings("unchecked") List<StudentCourseRecordInfo> studentCourseRecords = (List<StudentCourseRecordInfo>) getCacheResult( cacheKey);/*from ww w .ja va2 s . com*/ if (studentCourseRecords == null) { studentCourseRecords = getNextDecorator().getCompletedCourseRecords(personId, contextInfo); putCacheResult(cacheKey, studentCourseRecords); } return studentCourseRecords; }
From source file:org.perfrepo.web.controller.reports.parametrized.TestExecutionTable.java
/** * Add TestExecutions, which belongs to specified Job to the table * * @param jobId - Jenkins Job Id//from w w w.j a v a 2 s . c o m * @param testExecutions - List of TestExecution, which belong to job * @param baseTEs - indicates if the base/comparison TestExecutions are added to the table. */ private void addTestExecutions(Long jobId, List<TestExecution> testExecutions, boolean baseTEs) { if (!baseTEs) { compareJobIds.add(jobId); if (compareTestExecutions == null) { compareTestExecutions = HashMultimap.create(); } } for (TestExecution te : testExecutions) { String[] paramValues = new String[parameterNames.size()]; for (TestExecutionParameter tep : te.getParameters()) { paramValues[parameterNames.indexOf(tep.getName())] = tep.getValue(); } MultiKey params = new MultiKey(paramValues); //only if we can compare the value with something in the table //first TEs (jobId) should always put value to the table if (baseTEs || table.containsRow(params)) { for (Value value : te.getValues()) { MultiKey columnKey = new MultiKey(jobId, value.getMetric().getName()); if (!baseTEs) { compareTestExecutions.put(jobId, te); } table.put(params, columnKey, value); // update best values Value bestValue = bestValues.get(params, value.getMetric().getName()); if (bestValue == null || compareValues(bestValue, value) < 0) { bestValues.put(params, value.getMetric().getName(), value); } } tags.putAll(jobId, te.getTags()); } } }
From source file:org.perfrepo.web.controller.reports.parametrized.TestExecutionTable.java
public Value getValue(Long jobId, String metricName, String[] parameters) { MultiKey rowKey = new MultiKey(parameters); MultiKey colKey = new MultiKey(jobId, metricName); return table.get(rowKey, colKey); }