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.qwazr.utils.StringUtils.java

/**
 * @param text//from   w ww . j a v a  2  s  .co  m
 * @param replacements
 * @return
 */
public static String replaceEach(String text, Map<String, Object> replacements) {
    if (replacements == null)
        return text;
    String[] search = ArrayUtils.toArray(replacements.keySet());
    String[] replace = ArrayUtils.toStringArray(replacements.values());
    return replaceEach(text, search, replace);
}

From source file:com.acc.filter.FilterSpringUtil.java

/**
 * The same as {@link #getSpringBean(HttpServletRequest, String, Class)} but uses ServletContext as the first
 * parameter. It might be used in places, where HttpServletRequest is not available, but ServletContext is.
 *///from w  w w  .  j  ava 2 s .co m
public static <T> T getSpringBean(final ServletContext servletContext, final String beanName,
        final Class<T> beanClass) {
    T ret = null;
    final WebApplicationContext appContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContext);

    if (StringUtils.isNotBlank(beanName)) {
        try {
            ret = (T) appContext.getBean(beanName);
        } catch (final NoSuchBeanDefinitionException nsbde) {
            LOG.warn("No bean found with the specified name. Trying to resolve bean using type...");
        }
    }
    if (ret == null) {
        if (beanClass == null) {
            LOG.warn("No bean could be resolved. Reason: No type specified.");
        } else {
            final Map<String, T> beansOfType = appContext.getBeansOfType(beanClass);
            if (beansOfType != null && !beansOfType.isEmpty()) {
                if (beansOfType.size() > 1) {
                    LOG.warn("More than one matching bean found of type " + beanClass.getSimpleName()
                            + ". Returning the first one found.");
                }
                ret = beansOfType.values().iterator().next();
            }
        }
    }
    return ret;
}

From source file:com.inclouds.hbase.utils.TableLocality.java

private static Map<String, List<Path>> optimizeLocality(Map<String, List<Path>> serverMap)
        throws FileNotFoundException, IOException {
    LOG.info("Optimize locality starts");
    Set<String> servers = serverMap.keySet();
    Collection<List<Path>> regions = serverMap.values();
    ArrayList<Path> allRegions = new ArrayList<Path>();
    for (List<Path> rr : regions) {
        allRegions.addAll(rr);// w  w  w .j  a va  2 s . co m
    }

    // For all regions find server with max locality index
    int max = 0;
    Map<String, List<Path>> opt = new HashMap<String, List<Path>>();
    for (Path r : allRegions) {

        max = 0;
        String h = null;
        List<BlockLocation> blocks = getAllBlockLocations(r);
        for (String host : servers) {
            int locality = localityForServerBlocks(host, blocks);
            if (locality > max) {
                max = locality;
                h = host;
            }

        }

        LOG.info(r + " s=" + h + " locality=" + max);

        List<Path> pp = opt.get(h);
        if (pp == null) {
            pp = new ArrayList<Path>();
            opt.put(h, pp);
        }
        pp.add(r);
    }

    for (String s : opt.keySet()) {
        LOG.info(s + " r=" + opt.get(s).size() + " locality=" + localityForServer(s, opt.get(s)));

    }

    return opt;
}

From source file:org.orbeon.oxf.xforms.submission.XFormsSubmissionUtils.java

/**
 * Returns whether there is at least one relevant upload control with pending upload bound to any node of the given instance.
 *
 * @param containingDocument    current XFormsContainingDocument
 * @param currentInstance       instance to check
 * @return                      true iif condition is satisfied
 *///from  www .  j a v  a 2s.c  o  m
public static boolean hasBoundRelevantPendingUploadControls(XFormsContainingDocument containingDocument,
        XFormsInstance currentInstance) {
    if (containingDocument.countPendingUploads() > 0) { // don't bother if there is no pending upload
        final XFormsControls xformsControls = containingDocument.getControls();
        final Map uploadControls = xformsControls.getCurrentControlTree().getUploadControls();
        if (uploadControls != null) {
            for (Object o : uploadControls.values()) {
                final XFormsUploadControl currentControl = (XFormsUploadControl) o;
                if (currentControl.isRelevant() && containingDocument.isUploadPendingFor(currentControl)) {
                    final Item controlBoundItem = currentControl.getBoundItem();
                    if (controlBoundItem instanceof NodeInfo && currentInstance == currentInstance.model()
                            .getInstanceForNode((NodeInfo) controlBoundItem)) {
                        // Found one relevant upload control with pending upload bound to the instance we are submitting
                        return true;
                    }
                }
            }
        }
    }
    return false;
}

From source file:it.cilea.osd.jdyna.web.tag.JDynATagLibraryFunctions.java

public static boolean emptyMap(Map map) {
    if (map == null)
        return true;
    for (Object obj : map.values()) {
        if ((obj != null && obj instanceof Collection && ((Collection) obj).size() > 0)
                || (obj != null && !(obj instanceof Collection)))
            return false;
    }//from  w  ww.  j  av  a 2 s.c  om
    return true;
}

From source file:com.shouyingbao.pbs.core.framework.spring.context.utils.SpringContextUtil.java

/**
 * ?Class?/*from w w w.  j a  v a 2s .  c o  m*/
 * @param type
 * @return
 */
public static <T> T getBeanOfType(Class<T> type) {
    Map<String, T> beans = getBeansOfType(type);
    if (beans.size() == 0) {
        throw new NoSuchBeanDefinitionException(type,
                "Unsatisfied dependency of type [" + type + "]: expected at least 1 matching bean");
    }
    if (beans.size() > 1) {
        throw new NoSuchBeanDefinitionException(type,
                "expected single matching bean but found " + beans.size() + ": " + beans.keySet());
    }
    return beans.values().iterator().next();
}

From source file:com.ericsson.eiffel.remrem.publish.cli.CliOptions.java

/**
 * Lists the versions of publish and all loaded protocols  
 *///  w w  w.ja  v  a  2  s .  c o m
@SuppressWarnings({ "rawtypes", "unchecked" })
private static void printVersions() {
    Map versions = new VersionService().getMessagingVersions();
    Map<String, String> endpointVersions = (Map<String, String>) versions.get("endpointVersions");
    Map<String, String> serviceVersion = (Map<String, String>) versions.get("serviceVersion");

    if (serviceVersion != null) {
        System.out.print("REMReM Publish version ");
        for (String version : serviceVersion.values()) {
            System.out.println(version);
        }
    }
    if (endpointVersions != null) {
        System.out.println("Available endpoints");
        for (Map.Entry<String, String> entry : endpointVersions.entrySet()) {
            System.out.println(entry);
        }
    }
    exit(0);
}

From source file:org.openmrs.module.webservices.rest.resource.BaseRestDataResource.java

public static <E extends OpenmrsObject> void syncCollection(Collection<E> base, Collection<E> sync,
        Action2<Collection<E>, E> add, Action2<Collection<E>, E> remove) {
    Map<String, E> baseMap = new HashMap<String, E>(base.size());
    Map<String, E> syncMap = new HashMap<String, E>(sync.size());
    for (E item : base) {
        baseMap.put(item.getUuid(), item);
    }//from   ww  w .j a v a 2  s. c  om
    for (E item : sync) {
        syncMap.put(item.getUuid(), item);
    }

    for (E item : baseMap.values()) {
        if (syncMap.containsKey(item.getUuid())) {
            // Update the existing item
            E syncItem = syncMap.get(item.getUuid());
            syncItem.setId(item.getId());

            BeanUtils.copyProperties(syncItem, item);
        } else {
            // Delete item that is not in the sync collection
            remove.apply(base, item);
        }
    }

    for (E item : syncMap.values()) {
        if (!baseMap.containsKey(item.getUuid())) {
            // Add the item not in the base collection
            add.apply(base, item);
        }
    }
}

From source file:com.taobao.android.builder.tools.bundleinfo.BundleGraphExecutor.java

private static void handleCircleDependency(Map<String, BundleItem> bundleItemMap) {
    Map<String, Set<BundleItem>> circleMap = new HashMap<>();
    for (BundleItem bundleItem : bundleItemMap.values()) {
        Set<BundleItem> bundleItems = new HashSet<>();
        if (bundleItem.isLoop(bundleItem, new HashSet<>())) {
            bundleItem.getCircles(bundleItems, bundleItem);
            List<String> list = new ArrayList<>();
            for (BundleItem b : bundleItems) {
                list.add(b.bundleInfo.getPkgName());
            }/*from w ww  .  j  av  a 2  s  .c  om*/
            Collections.sort(list);
            String key = StringUtils.join(list.toArray(), ",");
            circleMap.put(key, bundleItems);
        }
    }

    //TODO
    for (Set<BundleItem> sets : circleMap.values()) {
        int i = 0;
        BundleItem main = null;
        for (BundleItem bundleItem : getOrderList(sets)) {
            if (i++ == 0) {
                main = bundleItem;
            } else {
                bundleItemMap.remove(bundleItem.bundleInfo.getPkgName());
                main.addBundleItem(bundleItem);
            }
        }
    }

}

From source file:com.textocat.textokit.postagger.opennlp.GeneratePipelineDescriptorForOpenNLPPosTagger.java

public static AnalysisEngineDescription getDescription() throws UIMAException, IOException {
    Map<String, MetaDataObject> aeDescriptions = Maps.newLinkedHashMap();
    aeDescriptions.put("tokenizer", TokenizerAPI.getAEImport());
    aeDescriptions.put("sentenceSplitter", SentenceSplitterAPI.getAEImport());
    Import posTaggerDescImport = new Import_impl();
    posTaggerDescImport.setName("com.textocat.textokit.postagger.postagger-ae");
    aeDescriptions.put("pos-tagger", posTaggerDescImport);
    ///* w w w . j a va 2 s. com*/
    return PipelineDescriptorUtils.createAggregateDescription(ImmutableList.copyOf(aeDescriptions.values()),
            ImmutableList.copyOf(aeDescriptions.keySet()));
}