List of usage examples for java.util Map values
Collection<V> values();
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step4MTurkOutputCollector.java
/** * Creates .success files for updating HITs in order to require more assignments. * * @param assignmentsPerHits actual assignments per HIT * @param hitTypeID type/*from w w w . jav a2s. c o m*/ * @param resultFile source MTurk file * @throws IOException IO exception */ static void prepareUpdateHITsFiles(Map<String, Integer> assignmentsPerHits, String hitTypeID, File resultFile) throws IOException { TreeSet<Integer> assignmentNumbers = new TreeSet<>(assignmentsPerHits.values()); System.out.println(assignmentsPerHits); // how many is required to be fully annotated final int fullyAnnotated = 5; assignmentNumbers.remove(fullyAnnotated); for (Integer i : assignmentNumbers) { // output file int annotationsRequired = fullyAnnotated - i; File file = new File(resultFile + "_requires_extra_assignments_" + annotationsRequired + ".success"); PrintWriter pw = new PrintWriter(file, "utf-8"); pw.println("hitid\thittypeid"); for (Map.Entry<String, Integer> entry : assignmentsPerHits.entrySet()) { if (i.equals(entry.getValue())) { pw.println(entry.getKey() + "\t" + hitTypeID); } } pw.close(); System.out.println( "Extra annotations required (" + annotationsRequired + "), saved to " + file.getAbsolutePath()); } }
From source file:NestUtil.java
/** * Get all fields of a class.//w ww .j a v a 2 s . c om * * @param clazz The class. * @return All fields of a class. */ public static Collection<Field> getFields(Class<?> clazz) { // if (log.isDebugEnabled()) { // log.debug("getFields(Class<?>) - start"); //} Map<String, Field> fields = new HashMap<String, Field>(); while (clazz != null) { for (Field field : clazz.getDeclaredFields()) { if (!fields.containsKey(field.getName())) { fields.put(field.getName(), field); } } clazz = clazz.getSuperclass(); } Collection<Field> returnCollection = fields.values(); // if (log.isDebugEnabled()) { // log.debug("getFields(Class<?>) - end"); // } return returnCollection; }
From source file:com.liveramp.hank.coordinator.Hosts.java
public static RuntimeStatisticsAggregator computeRuntimeStatisticsForHost( Map<Domain, RuntimeStatisticsAggregator> runtimeStatistics) { return RuntimeStatisticsAggregator.combine(runtimeStatistics.values()); }
From source file:com.firewallid.util.FISQL.java
public static String getFirstFieldInsertIfNotExist(Connection conn, String tableName, String field, Map<String, String> fields) throws SQLException { /* Query *///from ww w . j av a 2s . co m String query = "SELECT " + field + " FROM " + tableName + " WHERE " + Joiner.on(" = ? AND ").join(fields.keySet()) + " = ?"; /* Execute */ PreparedStatement pst = conn.prepareStatement(query); int i = 1; for (String value : fields.values()) { pst.setString(i, value); i++; } ResultSet executeQuery = pst.executeQuery(); if (executeQuery.next()) { return executeQuery.getString(field); } /* Row is not exists. Insert */ query = "INSERT INTO " + tableName + " (" + Joiner.on(", ").join(fields.keySet()) + ") VALUES (" + StringUtils.repeat("?, ", fields.size() - 1) + "?)"; pst = conn.prepareStatement(query); i = 1; for (String value : fields.values()) { pst.setString(i, value); i++; } if (pst.execute()) { return null; } return getFirstFieldInsertIfNotExist(conn, tableName, field, fields); }
From source file:com.stratio.crossdata.sh.utils.ConsoleUtils.java
/** * Convert QueryResult {@link com.stratio.crossdata.common.result.QueryResult} structure to String. * * @param queryResult {@link com.stratio.crossdata.common.result.QueryResult} from execution. * @return String representing the result. *///www .jav a 2 s . com private static String stringQueryResult(QueryResult queryResult) { if ((queryResult.getResultSet() == null) || queryResult.getResultSet().isEmpty()) { return System.lineSeparator() + "0 results returned"; } ResultSet resultSet = queryResult.getResultSet(); Map<String, Integer> colWidths = calculateColWidths(resultSet); String bar = StringUtils.repeat('-', getTotalWidth(colWidths) + (colWidths.values().size() * 3) + 1); StringBuilder sb = new StringBuilder(System.lineSeparator()); sb.append("Partial result: "); sb.append(!queryResult.isLastResultSet()); sb.append(System.lineSeparator()); sb.append(bar).append(System.lineSeparator()); sb.append("| "); List<String> columnNames = new ArrayList<>(); for (ColumnMetadata columnMetadata : resultSet.getColumnMetadata()) { sb.append(StringUtils.rightPad(columnMetadata.getName().getColumnNameToShow(), colWidths.get(columnMetadata.getName().getColumnNameToShow()) + 1)).append("| "); columnNames.add(columnMetadata.getName().getColumnNameToShow()); } sb.append(System.lineSeparator()); sb.append(bar); sb.append(System.lineSeparator()); for (Row row : resultSet) { sb.append("| "); for (String columnName : columnNames) { String str = String.valueOf(row.getCell(columnName.toLowerCase()).getValue()); sb.append(StringUtils.rightPad(str, colWidths.get(columnName.toLowerCase()))); sb.append(" | "); } sb.append(System.lineSeparator()); } sb.append(bar).append(System.lineSeparator()); return sb.toString(); }
From source file:cc.kave.commons.pointsto.evaluation.runners.ProjectStoreRunner.java
private static void methodPropabilities(Collection<ICoReTypeName> types, ProjectUsageStore store) throws IOException { ICoReTypeName stringType = Iterables.find(types, t -> t.getClassName().equals("String")); Map<ICoReMethodName, Integer> methods = new HashMap<>(); for (Usage usage : store.load(stringType)) { for (CallSite cs : usage.getReceiverCallsites()) { Integer currentCount = methods.getOrDefault(cs.getMethod(), 0); methods.put(cs.getMethod(), currentCount + 1); }//from w ww . j a v a 2 s.com } double total = methods.values().stream().mapToInt(i -> i).sum(); List<Map.Entry<ICoReMethodName, Integer>> methodEntries = new ArrayList<>(methods.entrySet()); methodEntries .sort(Comparator.<Map.Entry<ICoReMethodName, Integer>>comparingInt(e -> e.getValue()).reversed()); double mrr = 0; double rank = 1.0; for (Map.Entry<ICoReMethodName, Integer> method : methodEntries) { double probability = method.getValue() / total; mrr += probability * (1.0 / rank); ++rank; System.out.printf(Locale.US, "%s\t%.3f\n", method.getKey().getName(), probability); } System.out.println(mrr); }
From source file:br.com.suricattus.surispring.spring.security.util.SecurityUtil.java
/** * Method that checks if the user has the given access expression. * /*from www. j a v a 2s.co m*/ * @see Spring Security Expression-Based Access Control * @param access * @return */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static boolean isAuthorized(String access) { Map<String, SecurityExpressionHandler> expressionHandlres = ApplicationContextUtil.getContext() .getBeansOfType(SecurityExpressionHandler.class); SecurityExpressionHandler handler = (SecurityExpressionHandler) expressionHandlres.values().toArray()[0]; Expression accessExpression = handler.getExpressionParser().parseExpression(access); FilterInvocation f = new FilterInvocation(FacesUtils.getRequest(), FacesUtils.getResponse(), new FilterChain() { public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { throw new UnsupportedOperationException(); } }); return ExpressionUtils.evaluateAsBoolean(accessExpression, handler.createEvaluationContext(SecurityContextHolder.getContext().getAuthentication(), f)); }
From source file:de.tudarmstadt.ukp.dkpro.core.corenlp.internal.CoreNlp2DKPro.java
public static void convertCorefChains(JCas aJCas, Annotation aDocument) { List<CoreMap> sentences = aDocument.get(SentencesAnnotation.class); Map<Integer, CorefChain> chains = aDocument.get(CorefCoreAnnotations.CorefChainAnnotation.class); if (chains != null) { for (CorefChain chain : chains.values()) { CoreferenceLink last = null; for (CorefMention mention : chain.getMentionsInTextualOrder()) { CoreLabel beginLabel = sentences.get(mention.sentNum - 1).get(TokensAnnotation.class) .get(mention.startIndex - 1); CoreLabel endLabel = sentences.get(mention.sentNum - 1).get(TokensAnnotation.class) .get(mention.endIndex - 2); CoreferenceLink link = new CoreferenceLink(aJCas, beginLabel.get(TokenKey.class).getBegin(), endLabel.get(TokenKey.class).getEnd()); if (mention.mentionType != null) { link.setReferenceType(mention.mentionType.toString()); }//from ww w. ja v a 2s .c om if (last == null) { // This is the first mention. Here we'll initialize the chain CoreferenceChain corefChain = new CoreferenceChain(aJCas); corefChain.setFirst(link); corefChain.addToIndexes(); } else { // For the other mentions, we'll add them to the chain. last.setNext(link); } last = link; link.addToIndexes(); } } } }
From source file:com.rsa.redchallenge.standaloneapp.utils.RestInteractor.java
private static Object[] getObjectParams(Map<String, Object> params) { //RestTemplate considers curly braces {...} in the given URL as a placeholder for URI variables and tries to replace them based on their name //hence passing the values as it gets replaced by {} if (params != null && !params.isEmpty()) { return params.values().toArray(); }//from ww w.ja v a2 s .c o m return new Object[0]; }
From source file:com.google.gwt.dev.javac.CompilationStateBuilder.java
private static void invalidateUnitsWithInvalidRefs(TreeLogger logger, Map<String, CompilationUnit> resultUnits, Set<ContentId> set) { Set<CompilationUnit> validResultUnits = new HashSet<CompilationUnit>(resultUnits.values()); CompilationUnitInvalidator.retainValidUnits(logger, validResultUnits, set); for (Entry<String, CompilationUnit> entry : resultUnits.entrySet()) { CompilationUnit unit = entry.getValue(); if (unit.isCompiled() && !validResultUnits.contains(unit)) { entry.setValue(new InvalidCompilationUnit(unit)); }//from ww w . j av a 2 s. c o m } }