Example usage for java.util Map containsKey

List of usage examples for java.util Map containsKey

Introduction

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

Prototype

boolean containsKey(Object key);

Source Link

Document

Returns true if this map contains a mapping for the specified key.

Usage

From source file:org.fcrepo.camel.processor.EventProcessor.java

@SuppressWarnings("unchecked")
private static Map<String, List<String>> getValuesFromMap(final Map body) {
    final Map<String, Object> values = (Map<String, Object>) body;
    final Map<String, List<String>> data = new HashMap<>();
    if (values.containsKey("@id")) {
        data.put(FCREPO_URI, singletonList((String) values.get("@id")));
    }/*from   w w  w.  jav a2  s.com*/
    if (values.containsKey("id")) {
        data.putIfAbsent(FCREPO_URI, singletonList((String) values.get("id")));
    }

    if (values.containsKey("@type")) {
        data.put(FCREPO_RESOURCE_TYPE, (List<String>) values.get("@type"));
    }
    if (values.containsKey("type")) {
        data.putIfAbsent(FCREPO_RESOURCE_TYPE, (List<String>) values.get("type"));
    }

    final Map<String, Object> wasGeneratedBy = (Map<String, Object>) values.get("wasGeneratedBy");

    if (wasGeneratedBy != null) {
        if (wasGeneratedBy.containsKey("type")) {
            data.put(FCREPO_EVENT_TYPE, (List<String>) wasGeneratedBy.get("type"));
        }
        data.put(FCREPO_EVENT_ID, singletonList((String) wasGeneratedBy.get("identifier")));
        data.put(FCREPO_DATE_TIME, singletonList((String) wasGeneratedBy.get("atTime")));
    }

    final List<Map<String, String>> wasAttributedTo = (List<Map<String, String>>) values.get("wasAttributedTo");
    if (wasAttributedTo != null) {
        data.put(FCREPO_AGENT, wasAttributedTo.stream().map(agent -> agent.get("name")).collect(toList()));
    }

    return data;
}

From source file:ca.sfu.federation.utils.IContextUtils.java

/**
 * Get the next available element name for the given base name.
 * @param Context Context/*w w  w .  ja v a 2 s.  c o m*/
 * @param Name Base name
 * @return 
 */
public static String getNextName(IContext Context, String Name) {
    Map<String, INamed> map = Context.getElementMap();
    if (map.containsKey(Name)) {
        int count = 1;
        while (count > 0 && count < 100000) {
            String nextname = Name + "_" + count;
            if (!map.containsKey(nextname)) {
                return nextname;
            }
            count++;
        }

    }
    return Name;
}

From source file:Main.java

/**
 * Returns a {@link Map}&lt;V,{@link Set}&lt;K&gt;&gt; build by exchange
 * key and value of original {@code map}. All couple (K,V) are kept by
 * this operation./*www . j a va 2  s  .  com*/
 * <p>
 * Original map is not modify by this operation.
 *
 * @param <K>
 *            The type of the key of the initial map, the type of the value
 *            in result {@link Map}{@link Set}
 * @param <V>
 *            The type of the value of the initial map, the type of the key
 *            in result {@link Map}{@link Set}
 * @param map
 *            The map
 * @param mapSupplier
 *            The {@link Map} {@link Supplier}
 * @param setSupplier
 *            The {@link Set} {@link Supplier}
 * @return a {@link Map} build using {@link HashMap} {@link Set}
 */
public static <K, V> Map<V, Set<K>> reverseMap(@Nonnull final Map<K, V> map,
        @Nonnull final Supplier<Map<V, Set<K>>> mapSupplier, @Nonnull final Supplier<Set<K>> setSupplier) {
    final Map<V, Set<K>> reverseMap = mapSupplier.get();

    for (final Map.Entry<K, V> entry : map.entrySet()) {
        final K oldKey = entry.getKey();
        final V oldValue = entry.getValue();
        final Set<K> set;

        if (reverseMap.containsKey(oldValue)) {
            set = reverseMap.get(oldValue);
        } else {
            set = setSupplier.get();

            reverseMap.put(oldValue, set);
        }
        set.add(oldKey);
    }

    return reverseMap;
}

From source file:com.turn.ttorrent.tracker.client.HTTPTrackerClient.java

@CheckForNull
public static HTTPTrackerMessage toMessage(@Nonnull HttpResponse response,
        @CheckForSigned long maxContentLength) throws IOException {
    HttpEntity entity = response.getEntity();
    if (entity == null) // Usually 204-no-content, etc.
        return null;
    try {/*from   w  w  w . ja v  a  2  s . c  o  m*/
        if (maxContentLength >= 0) {
            long contentLength = entity.getContentLength();
            if (contentLength >= 0)
                if (contentLength > maxContentLength)
                    throw new IllegalArgumentException(
                            "ContentLength was too big: " + contentLength + ": " + response);
        }

        InputStream in = entity.getContent();
        if (in == null)
            return null;
        try {
            StreamBDecoder decoder = new StreamBDecoder(in);
            BEValue value = decoder.bdecodeMap();
            Map<String, BEValue> params = value.getMap();
            // TODO: "warning message"
            if (params.containsKey("failure reason"))
                return HTTPTrackerErrorMessage.fromBEValue(params);
            else
                return HTTPAnnounceResponseMessage.fromBEValue(params);
        } finally {
            Closeables.close(in, true);
        }
    } catch (InvalidBEncodingException e) {
        throw new IOException("Failed to parse response " + response, e);
    } catch (TrackerMessage.MessageValidationException e) {
        throw new IOException("Failed to parse response " + response, e);
    } finally {
        EntityUtils.consumeQuietly(entity);
    }
}

From source file:edu.umass.cs.gnsserver.localnameserver.LocalNameServerOptions.java

/**
 * Initializes global parameter options from command line and config file options
 * that are not handled elsewhere./*from   w  ww  . j a  v  a  2  s .c  o m*/
 *
 * @param allValues
 */
public static synchronized void initializeFromOptions(Map<String, String> allValues) {
    if (initialized) {
        return;
    }

    initialized = true;
    if (allValues == null) {
        return;
    }

    if (!allValues.containsKey(DISABLE_SSL)) {
        disableSSL = ReconfigurationConfig.getClientSSLMode() == SSL_MODES.CLEAR;
        // arun
        // ReconfigurationConfig.setClientPortOffset(100);
    } else {
        disableSSL = true;
    }
    System.out.println("LNS: SSL is " + (disableSSL ? "disabled" : "enabled"));
}

From source file:com.github.christofluyten.experiment.MeasureGendreau.java

static <T extends Enum<?>> StringBuilder appendValuesTo(StringBuilder sb, Map<T, Object> props,
        Iterable<T> keys) {
    final List<Object> values = new ArrayList<>();
    for (final T p : keys) {
        checkArgument(props.containsKey(p));
        values.add(props.get(p));/*  w  ww  .j a va  2 s  . c o  m*/
    }
    Joiner.on(",").appendTo(sb, values);
    return sb;
}

From source file:org.apache.solr.handler.TestBlobHandler.java

public static void postData(CloudSolrClient cloudClient, String baseUrl, String blobName, ByteBuffer bytarr)
        throws IOException {
    HttpPost httpPost = null;/*  w ww .  j a v  a 2s.  c  o m*/
    HttpEntity entity;
    String response = null;
    try {
        httpPost = new HttpPost(baseUrl + "/.system/blob/" + blobName);
        httpPost.setHeader("Content-Type", "application/octet-stream");
        httpPost.setEntity(new ByteArrayEntity(bytarr.array(), bytarr.arrayOffset(), bytarr.limit()));
        entity = cloudClient.getLbClient().getHttpClient().execute(httpPost).getEntity();
        try {
            response = EntityUtils.toString(entity, StandardCharsets.UTF_8);
            Map m = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
            assertFalse("Error in posting blob " + getAsString(m), m.containsKey("error"));
        } catch (JSONParser.ParseException e) {
            log.error("$ERROR$", response, e);
            fail();
        }
    } finally {
        httpPost.releaseConnection();
    }
}

From source file:fr.inria.lille.repair.nopol.NoPolLauncher.java

private static void displayResult(NoPol nopol, List<Patch> patches, long executionTime) {
    System.out.println("----INFORMATION----");
    List<CtType<?>> allClasses = nopol.getSpooner().spoonFactory().Class().getAll();
    int nbMethod = 0;
    for (int i = 0; i < allClasses.size(); i++) {
        CtType<?> ctSimpleType = allClasses.get(i);
        if (ctSimpleType instanceof CtClass) {
            Set methods = ((CtClass) ctSimpleType).getMethods();
            nbMethod += methods.size();// w ww  .j a  v  a2s. com
        }
    }
    System.out.println("Nb classes : " + allClasses.size());
    System.out.println("Nb methods : " + nbMethod);
    BitSet coverage = NoPol.currentStatement.getCoverage();
    int countStatementSuccess = 0;
    int countStatementFailed = 0;
    int nextTest = coverage.nextSetBit(0);
    while (nextTest != -1) {
        TestResult testResult = nopol.getgZoltar().getGzoltar().getTestResults().get(nextTest);
        if (testResult.wasSuccessful()) {
            countStatementSuccess += testResult.getCoveredComponents().size();
        } else {
            countStatementFailed += testResult.getCoveredComponents().size();
        }
        nextTest = coverage.nextSetBit(nextTest + 1);
    }
    System.out
            .println("Nb statements: " + nopol.getgZoltar().getGzoltar().getSpectra().getNumberOfComponents());
    System.out.println(
            "Nb statement executed by the passing tests of the patched line: " + countStatementSuccess);
    System.out
            .println("Nb statement executed by the failing tests of the patched line: " + countStatementFailed);
    System.out.println("Nb unit tests : " + nopol.getgZoltar().getGzoltar().getTestResults().size());
    System.out.println("Nb Statements Analyzed : " + SynthesizerFactory.getNbStatementsAnalysed());
    System.out.println(
            "Nb Statements with Angelic Value Found : " + DefaultSynthesizer.getNbStatementsWithAngelicValue());
    if (Config.INSTANCE.getSynthesis() == Config.NopolSynthesis.SMT) {
        System.out.println("Nb inputs in SMT : " + DefaultSynthesizer.getDataSize());
        System.out.println("Nb SMT level: " + ConstraintBasedSynthesis.level);
        if (ConstraintBasedSynthesis.operators != null) {
            System.out.println("Nb SMT components: [" + ConstraintBasedSynthesis.operators.size() + "] "
                    + ConstraintBasedSynthesis.operators);
            Iterator<Operator<?>> iterator = ConstraintBasedSynthesis.operators.iterator();
            Map<Class, Integer> mapType = new HashMap<>();
            while (iterator.hasNext()) {
                Operator<?> next = iterator.next();
                if (!mapType.containsKey(next.type())) {
                    mapType.put(next.type(), 1);
                } else {
                    mapType.put(next.type(), mapType.get(next.type()) + 1);
                }
            }
            for (Iterator<Class> patchIterator = mapType.keySet().iterator(); patchIterator.hasNext();) {
                Class next = patchIterator.next();
                System.out.println("                  " + next + ": " + mapType.get(next));
            }
        }

        System.out.println("Nb variables in SMT : " + DefaultSynthesizer.getNbVariables());
    }
    System.out.println("Nb run failing test  : " + nbFailingTestExecution);
    System.out.println("Nb run passing test : " + nbPassedTestExecution);
    System.out.println("NoPol Execution time : " + executionTime + "ms");

    if (patches != null && !patches.isEmpty()) {
        System.out.println("----PATCH FOUND----");
        for (Patch patch : patches) {
            System.out.println(patch);
        }
    }
}

From source file:org.unidle.test.Conditions.java

public static Condition<Map<?, ?>> containsKey(final Object key) {
    return new Condition<Map<?, ?>>(format("contains key: %s", key)) {
        @Override//from   w  w  w .ja v a  2s.co m
        public boolean matches(final Map<?, ?> value) {
            return value.containsKey(key);
        }
    };
}

From source file:data.intelligence.platform.yarn.etl.io.CodecPool.java

@SuppressWarnings("unchecked")
private static <T> void payback(Map<Class<T>, List<T>> pool, T codec) {
    if (codec != null) {
        Class<T> codecClass = (Class<T>) codec.getClass();
        synchronized (pool) {
            if (!pool.containsKey(codecClass)) {
                pool.put(codecClass, new ArrayList<T>());
            }//  w  w w  . j a  v a 2 s  .  c o m

            List<T> codecList = pool.get(codecClass);
            synchronized (codecList) {
                codecList.add(codec);
            }
        }
    }
}