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:org.bigtester.ate.GlobalUtils.java

/**
 * Find data source bean.//  ww  w .  j a  v  a 2s. c o  m
 *
 * @param appCtx
 *            the app ctx
 * @return the data source
 * @throws NoSuchBeanDefinitionException
 *             the no such bean definition exception
 */
public static IMyWebDriver findMyWebDriver(ApplicationContext appCtx) throws NoSuchBeanDefinitionException {
    Map<String, IMyWebDriver> drivers = appCtx.getBeansOfType(IMyWebDriver.class);

    if (drivers.isEmpty()) {
        throw new NoSuchBeanDefinitionException(DataSource.class);
    } else {
        IMyWebDriver retDriver = drivers.values().iterator().next();
        if (null == retDriver) {
            throw new NoSuchBeanDefinitionException(DataSource.class);
        } else {
            return retDriver;
        }
    }

}

From source file:org.bigtester.ate.GlobalUtils.java

/**
 * Find step data logger bean.//from   w ww. j  av a 2s . c o m
 *
 * @param appCtx the app ctx
 * @return the step data logger
 * @throws NoSuchBeanDefinitionException the no such bean definition exception
 */
public static StepDataLogger findStepDataLoggerBean(ApplicationContext appCtx)
        throws NoSuchBeanDefinitionException {
    Map<String, StepDataLogger> loggers = appCtx.getBeansOfType(StepDataLogger.class);

    if (loggers.isEmpty()) {
        throw new NoSuchBeanDefinitionException(TestCase.class);
    } else {
        StepDataLogger retVal = loggers.values().iterator().next();
        if (null == retVal) {
            throw new NoSuchBeanDefinitionException(TestCase.class);
        } else {
            return retVal;
        }
    }
}

From source file:de.tudarmstadt.ukp.dkpro.core.mallet.internal.wordembeddings.MalletEmbeddingsUtils.java

/**
 * Read embeddings in text format from an InputStream.
 * Each line is expected to have a whitespace-separated list {@code <token> <value1> <value2> ...}.
 *
 * @param inputStream an {@link InputStream}
 * @param hasHeader   if true, read size and dimensionality from the first line
 * @return a {@code Map<String, double[]>} mapping each token to a vector.
 * @throws IOException if the input file cannot be read
 *///from   www.  j  ava  2s .  c  om
public static Map<String, double[]> readEmbeddingFileTxt(InputStream inputStream, boolean hasHeader)
        throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));

    final int dimensions;
    final int size;

    if (hasHeader) {
        String[] header = reader.readLine().split(" ");
        assert header.length == 2;
        size = Integer.parseInt(header[0]);
        dimensions = Integer.parseInt(header[1]);
    } else {
        dimensions = -1;
        size = -1;
    }

    Map<String, double[]> embeddings = reader.lines().map(MalletEmbeddingsUtils::lineToEmbedding)
            .collect(Collectors.toMap(Pair::getKey, Pair::getValue));
    reader.close();

    /* assert size and dimension */
    if (hasHeader) {
        /* check that size read matches header information */
        LOG.debug("Checking number and vector sizes for all embeddings.");
        assert size == embeddings.size();
        assert embeddings.values().stream().allMatch(vector -> dimensions == vector.length);
    } else {
        LOG.debug("Checking vector sizes for all embeddings.");
        int firstLength = embeddings.values().stream().findAny().get().length;
        assert embeddings.values().stream().allMatch(vector -> firstLength == vector.length);
    }

    return embeddings;
}

From source file:net.greghaines.jesque.web.controller.JesqueController.java

private static List<WorkerInfo> combineWorkerInfos(final Map<?, List<WorkerInfo>> hostMap) {
    final List<WorkerInfo> allWorkers = new LinkedList<WorkerInfo>();
    for (final List<WorkerInfo> hostWorkers : hostMap.values()) {
        allWorkers.addAll(hostWorkers);/*from   www.ja va  2 s .com*/
    }
    return allWorkers;
}

From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.agent.KubernetesCacheDataConverter.java

/**
 * To ensure the entire relationship graph is bidirectional, invert any relationship entries here to point back at the
 * resource being cached (key).//w  ww .jav a2s .  com
 */
static List<CacheData> invertRelationships(CacheData cacheData) {
    String key = cacheData.getId();
    Keys.CacheKey parsedKey = Keys.parseKey(key)
            .orElseThrow(() -> new IllegalStateException("Cache data produced with illegal key format " + key));
    String group = parsedKey.getGroup();
    Map<String, Collection<String>> relationshipGroupings = cacheData.getRelationships();
    List<CacheData> result = new ArrayList<>();

    for (Collection<String> relationships : relationshipGroupings.values()) {
        for (String relationship : relationships) {
            invertSingleRelationship(group, key, relationship).flatMap(cd -> {
                result.add(cd);
                return Optional.empty();
            });
        }
    }

    return result;
}

From source file:net.sf.maltcms.chromaui.project.spi.DBProjectFactory.java

private static void initGroups(LinkedHashSet<String> groups, Map<File, String> fileToGroup,
        LinkedHashMap<String, Set<File>> groupToFile) {
    groups.addAll(fileToGroup.values());
    for (String group : groups) {
        for (File key : fileToGroup.keySet()) {
            if (fileToGroup.get(key).equals(group)) {
                if (groupToFile.containsKey(group)) {
                    Set<File> s = groupToFile.get(group);
                    s.add(key);//from   ww w  .j  a va2 s.  c o  m
                } else {
                    Set<File> s = new LinkedHashSet<>();
                    s.add(key);
                    groupToFile.put(group, s);
                }

            }
        }
    }
}

From source file:org.bigtester.ate.GlobalUtils.java

/**
 * Find test project bean./* w  ww. j a  v  a 2s .c  om*/
 *
 * @param appCtx
 *            the app ctx
 * @return the test project
 * @throws NoSuchBeanDefinitionException
 *             the no such bean definition exception
 */
public static TestProject findTestProjectBean(ApplicationContext appCtx) throws NoSuchBeanDefinitionException {
    Map<String, TestProject> testProjects = appCtx.getBeansOfType(TestProject.class);

    if (testProjects.isEmpty()) {
        throw new NoSuchBeanDefinitionException(TestProject.class);
    } else {
        TestProject testProject = testProjects.values().iterator().next();
        if (null == testProject) {
            throw new NoSuchBeanDefinitionException(TestProject.class);
        } else {
            return testProject;
        }
    }

}

From source file:com.alibaba.dubbo.governance.web.common.pulltool.Tool.java

public static int countMapValues(Map<?, ?> map) {
    int total = 0;
    if (map != null && map.size() > 0) {
        for (Object value : map.values()) {
            if (value != null) {
                if (value instanceof Number) {
                    total += ((Number) value).intValue();
                } else if (value.getClass().isArray()) {
                    total += Array.getLength(value);
                } else if (value instanceof Collection) {
                    total += ((Collection<?>) value).size();
                } else if (value instanceof Map) {
                    total += ((Map<?, ?>) value).size();
                } else {
                    total += 1;/*from   ww  w  . ja v  a  2s  .c o m*/
                }
            }
        }
    }
    return total;
}

From source file:net.sf.maltcms.chromaui.project.spi.DBProjectFactory.java

private static void initSampleGroups(LinkedHashSet<String> sampleGroups, Map<File, String> fileToSampleGroup,
        LinkedHashMap<String, Set<File>> groupToFile) {
    sampleGroups.addAll(fileToSampleGroup.values());
    for (String sampleGroup : sampleGroups) {
        for (File key : fileToSampleGroup.keySet()) {
            if (fileToSampleGroup.get(key).equals(sampleGroup)) {
                if (groupToFile.containsKey(sampleGroup)) {
                    Set<File> s = groupToFile.get(sampleGroup);
                    s.add(key);/* w  ww  . j a v  a  2s.c  o  m*/
                } else {
                    Set<File> s = new LinkedHashSet<>();
                    s.add(key);
                    groupToFile.put(sampleGroup, s);
                }

            }
        }
    }
}

From source file:com.hillert.si.SpringIntegrationUtils.java

/**
 * Helper Method to dynamically determine and display input and output
 * directories as defined in the Spring Integration context.
 *
 * @param context Spring Application Context
 *//*from   w  w w  .ja  va 2s.  c o m*/
public static void displayDirectories(final ApplicationContext context) {

    final Map<String, FileReadingMessageSource> fileReadingMessageSources = context
            .getBeansOfType(FileReadingMessageSource.class);
    final Map<String, FileWritingMessageHandler> fileWritingMessageHandlers = context
            .getBeansOfType(FileWritingMessageHandler.class);

    final List<String> inputDirectories = new ArrayList<String>();
    final List<String> outputDirectories = new ArrayList<String>();

    for (final FileReadingMessageSource messageSource : fileReadingMessageSources.values()) {
        final File inDir = (File) new DirectFieldAccessor(messageSource).getPropertyValue("directory");
        inputDirectories.add(inDir.getAbsolutePath());
    }

    for (final FileWritingMessageHandler messageHandler : fileWritingMessageHandlers.values()) {
        final File outDir = (File) new DirectFieldAccessor(messageHandler)
                .getPropertyValue("destinationDirectory");
        outputDirectories.add(outDir.getAbsolutePath());
    }

    final StringBuilder stringBuilder = new StringBuilder();

    stringBuilder.append("\n=========================================================");
    stringBuilder.append("\n");

    for (final String inputDirectory : inputDirectories) {
        stringBuilder.append("\n    Input directory is: '" + inputDirectory + "'");
    }

    for (final String outputDirectory : outputDirectories) {
        stringBuilder.append("\n    Output directory is: '" + outputDirectory + "'");
    }

    stringBuilder.append("\n\n=========================================================");

    LOGGER.info(stringBuilder.toString());

}