Example usage for java.util Map values

List of usage examples for java.util Map values

Introduction

In this page you can find the example usage for java.util Map values.

Prototype

Collection<V> values();

Source Link

Document

Returns a Collection view of the values contained in this map.

Usage

From source file:com.wavemaker.tools.javaservice.JavaServiceDefinition.java

/**
 * Get a list of methods, excluding overloaded ones, biased towards the method with the least number of arguments
 * (in other words, if a method is overloaded, the instance with the fewest arguments is included in the return
 * value).//  w  w  w  . j  av a  2s  .  c  o  m
 * 
 * @param allMethods
 * @return
 */
public static Collection<Method> filterOverloadedMethods(List<Method> allMethods) {

    Map<String, Method> methodsMap = new HashMap<String, Method>();
    for (Method method : allMethods) {
        if (methodsMap.containsKey(method.getName())) {
            if (methodsMap.get(method.getName()).getParameterTypes().length > method
                    .getParameterTypes().length) {
                methodsMap.put(method.getName(), method);
            }
        } else {
            methodsMap.put(method.getName(), method);
        }
    }

    return methodsMap.values();
}

From source file:cc.redpen.Main.java

@SuppressWarnings("static-access")
public static int run(String... args) throws RedPenException {
    Options options = new Options();
    options.addOption("h", "help", false, "Displays this help information and exits");

    options.addOption(OptionBuilder.withLongOpt("format")
            .withDescription("Input file format (markdown,plain,wiki,asciidoc,latex,rest)").hasArg()
            .withArgName("FORMAT").create("f"));

    options.addOption(OptionBuilder.withLongOpt("conf").withDescription("Configuration file (REQUIRED)")
            .hasArg().withArgName("CONF FILE").create("c"));

    options.addOption(OptionBuilder.withLongOpt("result-format")
            .withDescription("Output result format (json,json2,plain,plain2,xml)").hasArg()
            .withArgName("RESULT FORMAT").create("r"));

    options.addOption(OptionBuilder.withLongOpt("limit").withDescription("Error limit number").hasArg()
            .withArgName("LIMIT NUMBER").create("l"));

    options.addOption(OptionBuilder.withLongOpt("sentence").withDescription("Input sentences").hasArg()
            .withArgName("INPUT SENTENCES").create("s"));

    options.addOption(OptionBuilder.withLongOpt("lang").withDescription("Language of error messages").hasArg()
            .withArgName("LANGUAGE").create("L"));

    options.addOption(OptionBuilder.withLongOpt("threshold")
            .withDescription("Threshold of error level (info, warn, error)").hasArg().withArgName("THRESHOLD")
            .create("t"));

    options.addOption(OptionBuilder.withLongOpt("version")
            .withDescription("Displays version information and exits").create("v"));

    CommandLineParser commandLineParser = new BasicParser();
    CommandLine commandLine;/*w  ww.  j  ava2 s.  c o m*/
    try {
        commandLine = commandLineParser.parse(options, args);
    } catch (ParseException e) {
        LOG.error("Error occurred in parsing command line options ");
        printHelp(options);
        return -1;
    }

    String inputFormat = "plain";
    String configFileName = null;
    String resultFormat = "plain";
    String inputSentence = null;
    String language = "en";
    String threshold = "error";

    int limit = DEFAULT_LIMIT;

    if (commandLine.hasOption("h")) {
        printHelp(options);
        return 0;
    }
    if (commandLine.hasOption("v")) {
        System.out.println(RedPen.VERSION);
        return 0;
    }
    if (commandLine.hasOption("f")) {
        inputFormat = commandLine.getOptionValue("f");
    }
    if (commandLine.hasOption("c")) {
        configFileName = commandLine.getOptionValue("c");
    }
    if (commandLine.hasOption("r")) {
        resultFormat = commandLine.getOptionValue("r");
    }
    if (commandLine.hasOption("l")) {
        limit = Integer.valueOf(commandLine.getOptionValue("l"));
    }
    if (commandLine.hasOption("L")) {
        language = commandLine.getOptionValue("L");
    }
    if (commandLine.hasOption("s")) {
        inputSentence = commandLine.getOptionValue("s");
    }
    if (commandLine.hasOption("t")) {
        threshold = commandLine.getOptionValue("t");
    }

    // set language
    if (language.equals("ja")) {
        Locale.setDefault(new Locale("ja", "JA"));
    } else {
        Locale.setDefault(new Locale("en", "EN"));
    }

    String[] inputFileNames = commandLine.getArgs();
    if (!commandLine.hasOption("f")) {
        inputFormat = guessInputFormat(inputFileNames);
    }

    File configFile = resolveConfigLocation(configFileName);
    if (configFile == null) {
        LOG.error("Configuration file is not found.");
        printHelp(options);
        return 1;
    }

    if (inputFileNames.length == 0 && inputSentence == null) {
        LOG.error("Input is not given");
        printHelp(options);
        return 1;
    }

    RedPen redPen;
    try {
        redPen = new RedPen(configFile);
    } catch (RedPenException e) {
        LOG.error("Failed to parse input files: " + e);
        return -1;
    }

    List<Document> documents = getDocuments(inputFormat, inputSentence, inputFileNames, redPen);
    Map<Document, List<ValidationError>> documentListMap = redPen.validate(documents, threshold);

    Formatter formatter = FormatterUtils.getFormatterByName(resultFormat);
    if (formatter == null) {
        LOG.error("Unsupported format: " + resultFormat + " - please use xml, plain, plain2, json or json2");
        return -1;
    }
    String result = formatter.format(documentListMap);
    System.out.println(result);

    long errorCount = documentListMap.values().stream().mapToLong(List::size).sum();

    if (errorCount > limit) {
        LOG.error("The number of errors \"{}\" is larger than specified (limit is \"{}\").", errorCount, limit);
        return 1;
    } else {
        return 0;
    }
}

From source file:ch.cyberduck.ui.cocoa.odb.EditorFactory.java

/**
 * @param file// ww w.j  a  v  a 2 s  .  co m
 * @return Installed applications suitable to edit the given file type. Does always include
 *         the default editor set in the Preferences
 */
public static Map<String, String> getInstalledEditors(final Local file) {
    if (log.isTraceEnabled()) {
        log.trace("getInstalledEditors:" + file);
    }
    if (null == file) {
        return getInstalledEditors();
    }
    if (!Preferences.instance().getBoolean("editor.kqueue.enable")) {
        return getInstalledEditors();
    }
    Map<String, String> editors = new HashMap<String, String>();
    for (String bundleIdentifier : file.getDefaultApplications()) {
        final String name = getApplicationName(bundleIdentifier);
        if (null == name) {
            continue;
        }
        editors.put(name, bundleIdentifier);
    }
    // Add the application set as the default editor in the Preferences to be always
    // included in the list of available editors.
    final String defaultEditor = defaultEditor();
    if (null != defaultEditor) {
        if (!editors.values().contains(defaultEditor)) {
            editors.put(getApplicationName(defaultEditor), defaultEditor);
        }
    }
    return editors;
}

From source file:com.aurel.track.admin.customize.category.filter.execute.loadItems.LoadItemLinksUtil.java

/**
 * Get the linked workItemIDs//from   www. j a  va  2  s . c o  m
 * @param linkedWorkItemIDsMap
 * @return
 */
private static SortedSet<Integer> getFlatItems(Map<Integer, SortedSet<Integer>> linkedWorkItemIDsMap) {
    //get the flat linked items
    SortedSet<Integer> linkedWorkItemIDsSet = new TreeSet<Integer>();
    if (linkedWorkItemIDsMap != null) {
        Iterator<SortedSet<Integer>> iterator = linkedWorkItemIDsMap.values().iterator();
        while (iterator.hasNext()) {
            linkedWorkItemIDsSet.addAll(iterator.next());
        }
    }
    return linkedWorkItemIDsSet;
}

From source file:org.matsim.contrib.drt.analysis.DynModeTripsAnalyser.java

public static String summarizeDetailedOccupancyStats(Map<Id<Vehicle>, double[]> vehicleDistances, String del,
        int maxcap) {
    DecimalFormat format = new DecimalFormat();
    format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
    format.setMinimumIntegerDigits(1);/*  ww w  .  j av a2 s . com*/
    format.setMaximumFractionDigits(2);
    format.setGroupingUsed(false);

    double[] sum = new double[maxcap + 1];

    for (double[] dist : vehicleDistances.values()) {
        double emptyD = dist[0] - dist[2];
        sum[0] += emptyD;
        for (int i = 3; i < maxcap + 3; i++) {
            sum[i - 2] += dist[i];
        }
    }
    String result = "";
    for (int i = 0; i <= maxcap; i++) {
        result = result + ";" + format.format(sum[i]);
    }

    return result;
}

From source file:com.opengamma.component.tool.ToolContextUtils.java

private static ComponentInfo getComponentInfo(ComponentServer componentServer, List<String> preferenceList,
        Class<?> type) {//from w  w  w . java  2  s.c om
    Map<String, ComponentInfo> infos = componentServer.getComponentInfoMap(type);
    if (preferenceList != null) {
        for (String preference : preferenceList) {
            ComponentInfo componentInfo = infos.get(preference);
            if (componentInfo != null) {
                return componentInfo;
            }
        }
    }
    infos.remove("test");
    if (infos.size() == 0) {
        return null;
    }
    if (infos.size() > 1) {
        s_logger.warn("Multiple remote components match: " + type.getSimpleName() + "::" + infos.keySet());
        return null;
    }
    return infos.values().iterator().next();
}

From source file:org.dswarm.wikidataimporter.WikibaseAPIClient.java

private static RxObservableInvoker buildBaseRequestWithCookies(final Map<String, NewCookie> cookies) {

    final RxWebTarget<RxObservableInvoker> rxWebTarget = rxWebTarget();

    RxInvocationBuilder<RxObservableInvoker> request = rxWebTarget.request().header(HttpHeaders.USER_AGENT,
            DSWARM_USER_AGENT_IDENTIFIER);

    if (cookies != null) {

        for (final Cookie cookie : cookies.values()) {

            request = request.cookie(cookie);
        }/*from   w  w  w  . ja  v a2  s  .co m*/
    }

    return request.rx();
}

From source file:edu.umass.cs.reconfiguration.reconfigurationutils.ConsistentReconfigurableNodeConfig.java

/**
 * A utility method to split a collection of names into batches wherein
 * names in each batch map to the same reconfigurator group. The set of
 * reconfigurators can be specified either as a NodeIDType or a String set
 * but not as an InetSocketAddress set (unless NodeIDType is
 * InetSocketAddress).//from   w  ww .ja va 2 s  . c o m
 * 
 * @param names
 * @param reconfigurators
 * @return A set of batches of names wherein names in each batch map to the
 *         same reconfigurator group.
 */
public static Collection<Set<String>> splitIntoRCGroups(Set<String> names, Set<?> reconfigurators) {
    if (reconfigurators.isEmpty())
        throw new RuntimeException("A nonempty set of reconfigurators must be specified.");
    ConsistentHashing<?> ch = new ConsistentHashing<>(reconfigurators);
    Map<String, Set<String>> batches = new HashMap<String, Set<String>>();
    for (String name : names) {
        String rc = ch.getNode(name).toString();
        if (!batches.containsKey(rc))
            batches.put(rc, new HashSet<String>());
        batches.get(rc).add(name); // no need to put again
    }
    return batches.values();
}

From source file:edu.tum.cs.conqat.quamoco.qiesl.QIESLEngine.java

/**
 * Converts expression with model names to expression with technical names.
 * If a model name cannot be resolved a {@link QIESLException} is thrown.
 *//*from  w w  w  .  jav a2 s .c om*/
protected static String toTechnicalExpression(String expression, Map<String, String> nameMapping)
        throws QIESLException {
    Matcher matcher = PATTERN_FOR_MEASURE_NAMES.matcher(expression);
    StringBuffer result = new StringBuffer();
    while (matcher.find()) {
        String match = matcher.group(1);
        if (!nameMapping.containsValue(match)) {
            throw new QIESLException("Unknown variable '" + match + "' in spec;" + " available names are '"
                    + nameMapping.values() + "'");
        }
        String replacement = toTechnicalName(match);
        matcher.appendReplacement(result, StringUtils.escapeRegexReplacementString(replacement));
    }
    matcher.appendTail(result);
    return result.toString();
}

From source file:com.alibaba.jstorm.ui.UIUtils.java

public static TableData getNettyMetricsTable(Map<String, MetricInfo> metrics, Integer window,
        Map<String, String> paramMap) {

    TableData nettyTable = new TableData();
    nettyTable.setName(MetricDef.NETTY + " Metrics " + StatBuckets.getShowTimeStr(window));

    List<String> nettyHeaders = nettyTable.getHeaders();
    nettyHeaders.add(UIDef.HEADER_NETWORKER_CONNECTION);
    nettyHeaders.addAll(getKeys(metrics.values()));

    List<Map<String, ColumnData>> nettyLines = nettyTable.getLines();
    for (Entry<String, MetricInfo> entry : metrics.entrySet()) {
        String connectionName = entry.getKey();
        MetricInfo metricInfo = entry.getValue();

        Map<String, ColumnData> line = getMetricLine(metricInfo, nettyHeaders, window);

        ColumnData columnData = getConnectionColumnData(paramMap, connectionName);
        line.put(UIDef.HEADER_NETWORKER_CONNECTION, columnData);

        nettyLines.add(line);//from   w w w.  jav a2 s . c  o  m
    }

    return nettyTable;
}