Example usage for java.util Map getOrDefault

List of usage examples for java.util Map getOrDefault

Introduction

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

Prototype

default V getOrDefault(Object key, V defaultValue) 

Source Link

Document

Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.

Usage

From source file:org.apache.solr.security.GenericHadoopAuthPlugin.java

@SuppressWarnings("rawtypes")
@Override/*from   w w  w . j a  v a2  s .  c o  m*/
public void init(Map<String, Object> pluginConfig) {
    try {
        String delegationTokenEnabled = (String) pluginConfig.getOrDefault(DELEGATION_TOKEN_ENABLED_PROPERTY,
                "false");
        authFilter = (Boolean.parseBoolean(delegationTokenEnabled)) ? new HadoopAuthFilter()
                : new AuthenticationFilter();

        // Initialize kerberos before initializing curator instance.
        boolean initKerberosZk = Boolean
                .parseBoolean((String) pluginConfig.getOrDefault(INIT_KERBEROS_ZK, "false"));
        if (initKerberosZk) {
            (new Krb5HttpClientBuilder()).getBuilder();
        }

        FilterConfig conf = getInitFilterConfig(pluginConfig);
        authFilter.init(conf);

        String httpClientBuilderFactory = (String) pluginConfig.get(HTTPCLIENT_BUILDER_FACTORY);
        if (httpClientBuilderFactory != null) {
            Class c = Class.forName(httpClientBuilderFactory);
            factory = (HttpClientBuilderFactory) c.newInstance();
        }

    } catch (ServletException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        throw new SolrException(ErrorCode.SERVER_ERROR,
                "Error initializing kerberos authentication plugin: " + e);
    }
}

From source file:org.codice.ddf.catalog.ui.metacard.associations.Associated.java

private void removeEdge(Edge edge, Map<String, Metacard> metacards,
        /*Mutable*/ Map<String, Metacard> changedMetacards) {
    String id = edge.parent.get(Metacard.ID).toString();
    Metacard target = changedMetacards.getOrDefault(id, metacards.get(id));
    ArrayList<String> values = Optional.of(target).map(m -> m.getAttribute(edge.relation))
            .map(Attribute::getValues).map(util::getStringList).orElseGet(ArrayList::new);
    values.remove(edge.child.get(Metacard.ID).toString());
    target.setAttribute(new AttributeImpl(edge.relation, values));
    changedMetacards.put(id, target);/* w  w w  .  j  a v a 2  s .  com*/
}

From source file:com.sk89q.craftbook.sponge.mechanics.variable.Variables.java

public String getVariable(String namespace, String key) {
    Map<String, String> map = variableStore.getOrDefault(namespace, new HashMap<>());
    return map.getOrDefault(key, null);
}

From source file:edu.cmu.lti.oaqa.baseqa.providers.ml.classifiers.LibSvmProvider.java

@Override
public Map<String, Double> infer(Map<String, Double> features) {
    svm_node[] x = IntStream.range(1, fid2feat.size() + 1).mapToObj(j -> {
        svm_node node = new svm_node();
        node.index = j;//w  w  w  .  ja  v a 2s .c o  m
        node.value = features.getOrDefault(fid2feat.get(j), 0.0);
        return node;
    }).toArray(svm_node[]::new);
    double[] values = new double[lid2label.size()];
    svm.svm_predict_values(model, x, values);
    int[] lids = new int[lid2label.size()];
    svm.svm_get_labels(model, lids);
    return IntStream.range(0, values.length).boxed()
            .collect(toMap(i -> lid2label.get(lids[i]), i -> values[i]));
}

From source file:st.redline.kernel.RedlineSmalltalk.java

@SuppressWarnings("unchecked")
private String importFor(String packageName, String className, String reference) {
    Map emptyMap = emptyMap();/*from   w  w  w.j  a v  a  2  s  .c o m*/
    // TODO.JCL remove this conditional when importing is implemented.
    if (reference.equals("Object"))
        return "st.redline.kernel.Object";
    Map<String, Map<String, String>> thePackage = imports.getOrDefault(packageName, emptyMap);
    Map<String, String> theClass = thePackage.getOrDefault(className, emptyMap);
    return theClass.getOrDefault(reference, null);
}

From source file:com.teradata.benchto.driver.loader.BenchmarkLoader.java

@SuppressWarnings("unchecked")
private List<Map<String, String>> extractVariableMapList(Map<String, Object> yaml) {
    Map<String, Map<String, Object>> variableMaps = (Map) yaml.getOrDefault(VARIABLES_KEY, newHashMap());
    List<Map<String, String>> variableMapList = variableMaps.values().stream().map(YamlUtils::stringifyMultimap)
            .flatMap(variableMap -> cartesianProduct(variableMap).stream()).collect(toList());

    if (variableMapList.isEmpty()) {
        variableMapList.add(newHashMap());
    }/*  w w w. j av a  2 s  .  c  o m*/

    return variableMapList;
}

From source file:cc.kave.commons.pointsto.evaluation.cv.StratifiedMethodsCVFoldBuilder.java

private Map<ICoReMethodName, Integer> countMethods(Iterable<Usage> usages) {
    Map<ICoReMethodName, Integer> methods = new HashMap<>();

    for (Usage usage : usages) {
        for (CallSite callsite : usage.getReceiverCallsites()) {
            ICoReMethodName method = callsite.getMethod();
            int count = methods.getOrDefault(method, 0) + 1;
            methods.put(method, count);/*from  w w w.  ja  v  a2s.c  o  m*/
        }
    }

    return methods;
}

From source file:dk.dbc.rawrepo.oai.OAIIdentifierCollectionIT.java

private void loadRecordsFrom(String... jsons) throws SQLException, IOException {
    Connection connection = pg.getConnection();
    connection.prepareStatement("SET TIMEZONE TO 'UTC'").execute();
    try (PreparedStatement rec = connection
            .prepareStatement("INSERT INTO oairecords (pid, changed, deleted) VALUES(?, ?::timestamp, ?)");
            PreparedStatement recSet = connection
                    .prepareStatement("INSERT INTO oairecordsets (pid, setSpec) VALUES(?, ?)")) {

        for (String json : jsons) {
            InputStream is = getClass().getClassLoader().getResourceAsStream(json);
            if (is == null) {
                throw new RuntimeException("Cannot find: " + json);
            }/*  ww w.j  a v  a2s  .co  m*/
            ObjectMapper objectMapper = new ObjectMapper();
            List<ObjectNode> array = objectMapper.readValue(is, List.class);
            for (Object object : array) {
                Map<String, Object> obj = (Map<String, Object>) object;
                rec.setString(1, (String) obj.get("pid"));
                rec.setString(2, (String) obj.getOrDefault("changed",
                        DateTimeFormatter.ISO_INSTANT.format(Instant.now().atZone(ZoneId.systemDefault()))));
                rec.setBoolean(3, (boolean) obj.getOrDefault("deleted", false));
                rec.executeUpdate();
                recSet.setString(1, (String) obj.get("pid"));
                List<Object> sets = (List<Object>) obj.get("sets");

                for (Object set : sets) {
                    recSet.setString(2, (String) set);
                    recSet.executeUpdate();
                }
            }
        }
    } catch (SQLException ex) {
        ex.printStackTrace();
        throw new RuntimeException(ex);
    }
}

From source file:org.opencb.biodata.tools.variant.converter.VariantTabix.java

public VcfSample decodeSample(List<String> formatLst, Map<String, String> data) {
    List<String> values = new ArrayList<>(formatLst.size());
    for (String f : formatLst) {
        values.add(data.getOrDefault(f, StringUtils.EMPTY).toString());
    }//  w ww.  ja  v a2  s  . co  m
    return VcfSample.newBuilder().addAllSampleValues(values).build();
}

From source file:it.larusba.neo4j.jdbc.http.driver.CypherExecutor.java

/**
 * Retrieve the Neo4j version from the server.
 *
 * @return A string that represent the neo4j server version
 *///w  w w .  j  a v a2s  .co  m
public String getServerVersion() {
    String result = "Unknown";

    // Prepare the headers query
    HttpGet request = new HttpGet(
            this.transactionUrl.replace("/db/data/transaction", "/db/manage/server/version"));

    // Adding default headers to the request
    for (Header header : this.getDefaultHeaders()) {
        request.addHeader(header.getName(), header.getValue());
    }

    // Make the request
    try (CloseableHttpResponse response = http.execute(request)) {
        try (InputStream is = response.getEntity().getContent()) {
            Map body = mapper.readValue(is, Map.class);
            result = (String) body.getOrDefault("version", result);
        }
    } catch (Exception e) {
        // do nothing there is the default value
    }

    return result;
}