Example usage for java.util Map containsValue

List of usage examples for java.util Map containsValue

Introduction

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

Prototype

boolean containsValue(Object value);

Source Link

Document

Returns true if this map maps one or more keys to the specified value.

Usage

From source file:org.openanzo.client.cli.CommandContext.java

Map<String, String> combinePrefixes(Map<String, String> userPrefixes, Map<String, String> inputPrefixes) {
    Map<String, String> results = new HashMap<String, String>(userPrefixes);
    for (Map.Entry<String, String> prefixEntry : inputPrefixes.entrySet()) {
        if (!userPrefixes.containsValue(prefixEntry.getValue())
                && !userPrefixes.containsKey(prefixEntry.getKey())) {
            results.put(prefixEntry.getKey(), prefixEntry.getValue());
        }// w  w w. j  a  v a  2 s .  c  om
    }
    return results;
}

From source file:org.jbpm.bpel.tools.WsdlServiceTool.java

protected Port generatePort(Binding binding, Definition serviceDefinition) throws WSDLException {
    // port/*from  w w w  .  ja  v a 2 s .c o m*/
    Port port = serviceDefinition.createPort();
    port.setBinding(binding);

    // namespace declaration for binding name
    String bindingNamespace = binding.getQName().getNamespaceURI();
    Map namespaces = serviceDefinition.getNamespaces();
    if (!namespaces.containsValue(bindingNamespace)) {
        String prefix = generateName("bindingNS", namespaces.keySet());
        serviceDefinition.addNamespace(prefix, bindingNamespace);
    }

    // soap address
    SOAPAddress soapAddress = (SOAPAddress) serviceDefinition.getExtensionRegistry().createExtension(Port.class,
            SOAPConstants.Q_ELEM_SOAP_ADDRESS);
    soapAddress.setLocationURI(ADDRESS_LOCATION_URI);
    port.addExtensibilityElement(soapAddress);

    return port;
}

From source file:com.googlecode.concurrentlinkedhashmap.ConcurrentMapTest.java

@Test(dataProvider = "guardedMap")
public void remove(Map<Integer, Integer> map) {
    map.put(1, 2);// w  ww.  ja v  a2s .  c o m
    assertThat(map.remove(1), is(2));
    assertThat(map.remove(1), is(nullValue()));
    assertThat(map.get(1), is(nullValue()));
    assertThat(map.containsKey(1), is(false));
    assertThat(map.containsValue(2), is(false));
    assertThat(map, is(emptyMap()));
}

From source file:com.orange.atk.graphAnalyser.LectureJATKResult.java

public String getcolor(Color color) {
    Map<String, Color> mapColor = CreateGraph.getMapColor();

    if (mapColor.containsValue(color)) {

        Set<String> cles = mapColor.keySet();
        Iterator<String> it = cles.iterator();
        while (it.hasNext()) {
            String cle = (String) it.next();
            Color tempcolor = mapColor.get(cle);
            if (tempcolor.equals(color))
                return cle;

        }// w w  w.j  ava2s  . c o  m

    }
    return null;
}

From source file:com.company.project.service.dao.RedisDaoTest.java

@Test
public void testSetGetMulti() {
    System.out.println("get");
    Map<String, Object> map = new HashMap<>();
    map.put("thekey1", "theValue1");
    map.put("thekey2", "theValue2");
    map.put("thekey3", "theValue3");

    redisDao.multiSet(map);//w  w  w  .  ja v  a2  s . c om

    List list = redisDao.multiGet(map.keySet());
    assertEquals(map.keySet().size(), list.size());
    for (Object string : list) {
        assertTrue(map.containsValue("" + string));
    }
    System.out.println("List:" + list);

    redisDao.delete(map.keySet());

    list = redisDao.multiGet(map.keySet());
    for (Object string : list) {
        assertNull(string);
    }
    System.out.println("List after delete:" + list);
}

From source file:org.jitsi.jirecon.StreamForwarder.java

/**
 * Find and get the <tt>MediaType</tt> ssrc which belongs to some endpoint.
 * <strong>Warning:</strong> An endpoint means a media stream source, each
 * media stream source generally contains two ssrc, one for audio stream and
 * one for video stream./*  ww  w  .  j  a v a 2s  .  co  m*/
 * 
 * @param ssrc indicates an endpoint.
 * @param mediaType is the <tt>MediaType</tt> which indicates which ssrc you
 *            want to get.
 * @return ssrc or -1 if not found
 */
private long getAssociatedSsrc(long ssrc, MediaType mediaType) {
    synchronized (endpointsSyncRoot) {
        if (endpoints != null && !endpoints.isEmpty()) {
            for (EndpointInfo endpoint : endpoints) {
                Map<MediaType, Long> ssrcs = endpoint.getSsrcs();

                if (ssrcs.size() < 2)
                    continue;

                if (ssrcs.containsValue(ssrc)) {
                    return ssrcs.get(mediaType);
                }
            }
        } else {
            logger.warn("The endpoints collection is empty!");
        }
    }

    return -1;
}

From source file:org.deri.iris.queryrewriting.SQLRewriter.java

public String getSQLRewriting(IRule query, final String sqlConstraint, final int nbNodes, final int startedFrom)
        throws SQLException {
    //LOGGER.debug("Translating " + query);
    final IBasicFactory bf = Factory.BASIC;

    final Map<String, String> aliasMap = new HashMap<String, String>();
    final Set<ITerm> processedTargetTerms = new HashSet<ITerm>();
    final List<String> targetList = new ArrayList<String>();
    final List<String> fromList = new ArrayList<String>();
    final List<String> whereList = new ArrayList<String>();

    // Disambiguate same predicates in the query body
    final Set<ILiteral> body = new LinkedHashSet<ILiteral>();
    int dis = 1;//  w w  w .ja  v a  2  s  .c o m
    for (final ILiteral l : query.getBody()) {
        final String p = l.getAtom().getPredicate().toString();
        String p_alias;
        if (aliasMap.containsValue(p)) {
            p_alias = Joiner.on("").join(p, "_", dis++);
        } else {
            p_alias = p;
        }
        aliasMap.put(p_alias, p);
        body.add(bf.createLiteral(l.isPositive(),
                bf.createPredicate(p_alias, l.getAtom().getPredicate().getArity()), l.getAtom().getTuple()));
    }
    query = bf.createRule(query.getHead(), body);

    try {
        final StringBuffer out = new StringBuffer();

        // Translate the Query
        for (int i = 0; i < query.getBody().size(); i++) {
            final ILiteral l = Iterators.get(query.getBody().iterator(), i);
            final String p = l.getAtom().getPredicate().getPredicateSymbol();
            fromList.add(p);

            int pos = 0;
            for (final ITerm t : l.getAtom().getTuple()) {
                pos++;
                if (query.getHeadVariables().contains(t) && !processedTargetTerms.contains(t)) {
                    // This is a head variable
                    targetList.add(
                            Joiner.on("").join(p, ".", StorageManager.getFields(aliasMap.get(p)).get(pos - 1)));
                    processedTargetTerms.add(t);
                }
                if (t instanceof StringTerm) {
                    if (aliasMap.containsKey(p)) {
                        whereList.add(Joiner.on("").join(p, ".",
                                StorageManager.getFields(aliasMap.get(p)).get(pos - 1), "=", t, ""));
                    }
                }
                for (int j = i + 1; j < query.getBody().size(); j++) {
                    final ILiteral lj = Iterators.get(query.getBody().iterator(), j);
                    final String pj = lj.getAtom().getPredicate().toString();
                    int posj = 0;
                    for (final ITerm jt : lj.getAtom().getTuple()) {
                        posj++;
                        if (jt.equals(t)) {
                            if (p.equalsIgnoreCase("I_CLASS")) {
                                final String whereAtom = Joiner.on("").join(p, ".",
                                        StorageManager.getFields(aliasMap.get(p)).get(pos - 1), "=", pj, ".",
                                        StorageManager.getFields(aliasMap.get(pj)).get(posj - 1));
                                whereList.add(whereAtom);
                            } else {
                                final String whereAtom = Joiner.on("").join(pj, ".",
                                        StorageManager.getFields(aliasMap.get(pj)).get(posj - 1), "=", p, ".",
                                        StorageManager.getFields(aliasMap.get(p)).get(pos - 1));
                                whereList.add(whereAtom);
                            }
                        }
                    }
                }
            }
        }

        // Building the target list
        if (targetList.size() == 0) {
            out.append("SELECT DISTINCT 'true'");
        } else {
            out.append("SELECT DISTINCT ");
            for (int i = 0; i < (targetList.size() - 1); i++) {
                out.append(targetList.get(i)).append(", ");
            }
            out.append(targetList.get(targetList.size() - 1));
        }

        // Building the from list
        out.append(" FROM ");
        final String vendor = StorageManager.getVendor();
        for (int i = 0; i < (fromList.size() - 1); i++) {
            if (aliasMap.get(fromList.get(i)).compareTo(fromList.get(i)) != 0) {
                if (vendor.compareTo("_ORACLE") == 0) {
                    out.append(aliasMap.get(fromList.get(i))).append(" ").append(fromList.get(i)).append(", ");
                } else if (vendor.compareTo("_MYSQL") == 0) {
                    out.append(aliasMap.get(fromList.get(i))).append(" AS ").append(fromList.get(i))
                            .append(", ");
                } else if (vendor.compareTo("_POSTGRES") == 0) {
                    out.append(StorageManager.getSchemaName()).append(".").append(aliasMap.get(fromList.get(i)))
                            .append(" AS ").append(fromList.get(i)).append(", ");
                } else
                    throw new SQLException("Unsupported Vendor: " + vendor);
            } else {
                if (vendor.equals("_POSTGRES")) {
                    out.append(StorageManager.getSchemaName()).append(".").append(fromList.get(i)).append(", ");
                } else {
                    out.append(fromList.get(i)).append(", ");
                }
            }
        }
        if (aliasMap.get(fromList.get(fromList.size() - 1)).compareTo(fromList.get(fromList.size() - 1)) != 0) {
            if (vendor.equals("_ORACLE")) {
                out.append(aliasMap.get(fromList.get(fromList.size() - 1))).append(" ")
                        .append(fromList.get(fromList.size() - 1));
            } else if (vendor.compareTo("_MYSQL") == 0) {
                out.append(aliasMap.get(fromList.get(fromList.size() - 1))).append(" AS ")
                        .append(fromList.get(fromList.size() - 1));
            } else if (vendor.compareTo("_POSTGRES") == 0) {
                out.append(StorageManager.getSchemaName()).append(".")
                        .append(aliasMap.get(fromList.get(fromList.size() - 1))).append(" AS ")
                        .append(fromList.get(fromList.size() - 1));
            } else
                throw new SQLException("Unsupported Vendor: " + vendor);
        } else {
            if (vendor.equals("_POSTGRES")) {
                out.append(StorageManager.getSchemaName()).append(".")
                        .append(fromList.get(fromList.size() - 1));
                out.append(", preferences.place ");
            } else {
                out.append(fromList.get(fromList.size() - 1));
            }
        }

        // Building the where list
        if (whereList.size() > 0) {
            out.append(" WHERE ");
            for (int i = 0; i < (whereList.size() - 1); i++) {
                out.append(whereList.get(i)).append(" AND ");
            }
            out.append(whereList.get(whereList.size() - 1));
            out.append("and business_categories.bs_id = place.bs_id " + sqlConstraint);

        }
        out.append("  limit " + nbNodes + " offset " + startedFrom);
        //LOGGER.debug("Q " + out.toString());
        return (out.toString());

    } catch (final SQLException e) {
        e.printStackTrace();
    }
    return (null);
}

From source file:de.mpg.escidoc.pubman.util.InternationalizationHelper.java

/**
 * Returns an array of SelectItems for the enum CreatorRole.
 * @param includeNoItemSelectedEntry if true an entry for NoItemSelected is added
 * @return array of SelectItems for CreatorRole
 *//*from w w w  .  j  av  a2s .c o  m*/
public SelectItem[] getSelectItemsCreatorRole(final boolean includeNoItemSelectedEntry) {
    ApplicationBean appBean = (ApplicationBean) getApplicationBean(ApplicationBean.class);
    Map<String, String> negativeRoles = appBean.getCreatorRoleMap();

    List<CreatorVO.CreatorRole> values = new ArrayList<CreatorVO.CreatorRole>();
    for (CreatorVO.CreatorRole role : CreatorVO.CreatorRole.values()) {
        values.add(role);
    }

    int i = 0;
    while (i < values.size()) {
        if (negativeRoles.containsValue(values.get(i).getUri())) {
            values.remove(i);
        } else {
            i++;
        }
    }

    return getSelectItemsForEnum(includeNoItemSelectedEntry, values.toArray());
}

From source file:org.ankus.mapreduce.algorithms.correlation.booleanset.CalculationBooleanSetReducer.java

@Override
protected void reduce(TextTwoWritableComparable key, Iterable<TextIntegerTwoPairsWritableComparable> values,
        Context context) throws IOException, InterruptedException {

    if (algorithmOption.equals(Constants.HAMMING_DISTACNE_FOR_BOOLEAN)) {
        int hammingDistance = 0;

        Map<String, Integer> itemID1Map = new HashMap<String, Integer>();
        Map<String, Integer> itemID2Map = new HashMap<String, Integer>();

        for (TextIntegerTwoPairsWritableComparable textIntegerPairsWritable : values) {
            itemID1Map.put(textIntegerPairsWritable.getText1().toString(),
                    textIntegerPairsWritable.getNumber1());
            itemID2Map.put(textIntegerPairsWritable.getText2().toString(),
                    textIntegerPairsWritable.getNumber2());
        }/* w w w. j  a  v  a  2 s  .c om*/

        char[] item1CharArray = itemID1Map.toString().toCharArray();
        char[] item2CharArray = itemID2Map.toString().toCharArray();

        int item1CharArrayLength = item1CharArray.length;
        int item2CharArrayLength = item2CharArray.length;

        if (itemID1Map.containsValue(itemID2Map))
            hammingDistance = 0;
        if (item1CharArrayLength != item2CharArrayLength) {
            hammingDistance = -1;
        } else {
            for (int i = 0; i < item1CharArrayLength; ++i) {
                if (itemID1Map.toString().charAt(i) == itemID2Map.toString().charAt(i)) {
                    hammingDistance += 0;
                } else if (itemID1Map.toString().charAt(i) != itemID2Map.toString().charAt(i)) {
                    ++hammingDistance;
                }
            }
        }
        context.write(key, new DoubleWritable(hammingDistance));

    } else if (algorithmOption.equals(Constants.DICE_COEFFICIENT)) {
        double diceCoefficient = 0.0d;
        int size1 = 0;
        int size2 = 0;

        Map<String, Integer> itemID1Map = new HashMap<String, Integer>();
        Map<String, Integer> itemID2Map = new HashMap<String, Integer>();

        for (TextIntegerTwoPairsWritableComparable textIntegerPairsWritable : values) {
            itemID1Map.put(textIntegerPairsWritable.getText1().toString(),
                    textIntegerPairsWritable.getNumber1());
            itemID2Map.put(textIntegerPairsWritable.getText2().toString(),
                    textIntegerPairsWritable.getNumber2());

            size1 += textIntegerPairsWritable.getNumber1();
            size2 += textIntegerPairsWritable.getNumber2();
        }

        // Find the intersection, and get the number of elements in that set.
        Collection<String> intersection = CollectionUtils.intersection(itemID1Map.entrySet(),
                itemID2Map.entrySet());

        diceCoefficient = (2.0 * (float) intersection.size()) / ((float) (size1 + size2));
        context.write(key, new DoubleWritable(Double.parseDouble(String.format("%.3f%n", diceCoefficient))));

    } else if (algorithmOption.equals(Constants.JACCARD_COEFFICIENT)) {
        double jaccardCoefficient = 0.0d;
        int unionSize = 0;

        Map<String, Integer> itemID1Map = new HashMap<String, Integer>();
        Map<String, Integer> itemID2Map = new HashMap<String, Integer>();

        for (TextIntegerTwoPairsWritableComparable textIntegerPairsWritable : values) {
            itemID1Map.put(textIntegerPairsWritable.getText1().toString(),
                    textIntegerPairsWritable.getNumber1());
            itemID2Map.put(textIntegerPairsWritable.getText2().toString(),
                    textIntegerPairsWritable.getNumber2());

            if ((textIntegerPairsWritable.getNumber1() + textIntegerPairsWritable.getNumber2()) >= 1) {
                unionSize += 1;
            }
        }

        Collection<String> intersection = CollectionUtils.intersection(itemID1Map.entrySet(),
                itemID2Map.entrySet());

        jaccardCoefficient = (float) intersection.size() / (float) unionSize;
        context.write(key, new DoubleWritable(Double.parseDouble(String.format("%.3f%n", jaccardCoefficient))));
    }
}

From source file:org.openmrs.module.xforms.buendia.BuendiaXformBuilder.java

/**
 * Creates a model binding node.//from   w ww.ja  va2 s . c  om
 * @param modelElement - the model node to add the binding to.
 * @param node         - the node whose binding to create.
 * @param bindings     - a hashtable of node bindings keyed by their names.
 * @return - the created binding node.
 */
private static Element createBindNode(Element modelElement, Element node, Map<String, Element> bindings,
        Map<String, String> problemList, Map<String, String> problemListItems) {
    Element bindNode = modelElement.createElement(NAMESPACE_XFORMS, null);
    bindNode.setName(NODE_BIND);
    String parentName = ((Element) node.getParent()).getName();
    String binding = node.getName();

    if (bindings.containsKey(binding)) {
        binding = parentName + "_" + binding;
        problemListItems.put(binding, parentName);
    } else {
        if (!(parentName.equalsIgnoreCase("obs") || parentName.equalsIgnoreCase("patient")
                || parentName.equalsIgnoreCase("encounter") || parentName.equalsIgnoreCase("problem_list")
                || parentName.equalsIgnoreCase("orders"))) {
            //binding = parentName + "_" + binding;
            //TODO Need to investigate why the above commented out code brings the no data
            // node found error in the form designer
        }
    }

    bindNode.setAttribute(null, ATTRIBUTE_ID, binding);

    String name = node.getName();
    String nodeset = getNodesetAttValue(node);

    //For problem list element bindings, we do not add the value part.
    if (parentName.equalsIgnoreCase(NODE_PROBLEM_LIST)) {
        problemList.put(name, name);
        nodeset = getNodePath(node);
    }

    //Check if this is an item of a problem list.
    if (problemList.containsKey(parentName)) {
        if (problemListItems.containsValue(name)) {
            throw new IllegalStateException(
                    "Original code would use repeatSharedKids here, despite it being null");
        }
        problemListItems.put(name, parentName);
    }

    bindNode.setAttribute(null, ATTRIBUTE_NODESET, nodeset);

    if (!((Element) ((Element) node.getParent()).getParent()).getName().equals(NODE_PROBLEM_LIST)) {
        modelElement.addChild(Element.ELEMENT, bindNode);
    }

    //store the binding node with the key being its id attribute.
    bindings.put(binding, bindNode);

    return bindNode;
}