Example usage for java.util Map putAll

List of usage examples for java.util Map putAll

Introduction

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

Prototype

void putAll(Map<? extends K, ? extends V> m);

Source Link

Document

Copies all of the mappings from the specified map to this map (optional operation).

Usage

From source file:gov.va.chir.tagline.dao.DatasetUtil.java

public static Instances createDataset(final Collection<Document> documents) {

    // Key = feature name | Value = number representing NUMERIC, NOMINAL, etc.
    final Map<String, Integer> featureType = new TreeMap<String, Integer>();

    // Key = feature name | Values = distinct values for NOMINAL values
    final Map<String, Set<String>> nominalFeatureMap = new HashMap<String, Set<String>>();

    final Set<String> labels = new TreeSet<String>();
    final Set<String> docIds = new TreeSet<String>();

    // First scan -- determine attribute values
    for (Document document : documents) {
        processFeatures(document.getFeatures(), featureType, nominalFeatureMap);
        docIds.add(document.getName());/*from  w  ww.j  a  va2s  .c  o m*/

        for (Line line : document.getLines()) {
            processFeatures(line.getFeatures(), featureType, nominalFeatureMap);

            labels.add(line.getLabel());
        }
    }

    final ArrayList<Attribute> attributes = new ArrayList<Attribute>();

    // Add Document and Line IDs as first two attributes
    //final Attribute docId = new Attribute(DOC_ID, (ArrayList<String>) null);
    final Attribute docId = new Attribute(DOC_ID, new ArrayList<String>(docIds));
    final Attribute lineId = new Attribute(LINE_ID);

    attributes.add(docId);
    attributes.add(lineId);

    // Build attributes
    for (String feature : featureType.keySet()) {
        final int type = featureType.get(feature);

        if (type == Attribute.NUMERIC) {
            attributes.add(new Attribute(feature));
        } else {
            if (nominalFeatureMap.containsKey(feature)) {
                attributes.add(new Attribute(feature, new ArrayList<String>(nominalFeatureMap.get(feature))));
            }
        }
    }

    // Add class attribute
    Attribute classAttr = new Attribute(LABEL, new ArrayList<String>(labels));
    attributes.add(classAttr);

    final Instances instances = new Instances("train", attributes, documents.size());

    // Second scan -- add data
    for (Document document : documents) {
        final Map<String, Object> docFeatures = document.getFeatures();

        for (Line line : document.getLines()) {
            final Instance instance = new DenseInstance(attributes.size());

            final Map<String, Object> lineFeatures = line.getFeatures();
            lineFeatures.putAll(docFeatures);

            instance.setValue(docId, document.getName());
            instance.setValue(lineId, line.getLineId());
            instance.setValue(classAttr, line.getLabel());

            for (Attribute attribute : attributes) {
                if (!attribute.equals(docId) && !attribute.equals(lineId) && !attribute.equals(classAttr)) {
                    final String name = attribute.name();
                    final Object obj = lineFeatures.get(name);

                    if (obj instanceof Double) {
                        instance.setValue(attribute, ((Double) obj).doubleValue());
                    } else if (obj instanceof Integer) {
                        instance.setValue(attribute, ((Integer) obj).doubleValue());
                    } else {
                        instance.setValue(attribute, obj.toString());
                    }
                }
            }

            instances.add(instance);
        }
    }

    // Set last attribute as class
    instances.setClassIndex(attributes.size() - 1);

    return instances;
}

From source file:com.ge.predix.uaa.token.lib.TestTokenUtil.java

private static Map<String, ?> createJWTAccessToken(final OAuth2AccessToken token, final String issuerId,
        final String userId, final String username, final String userEmail,
        final Collection<GrantedAuthority> clientScopes, final Set<String> requestedScopes,
        final String clientId, final Set<String> resourceIds, final String grantType, final String refreshToken,
        final String revocableHashSignature, final long issuedAtMillis, final String zoneId) {

    Map<String, Object> response = new LinkedHashMap<String, Object>();

    response.put(JTI, token.getAdditionalInformation().get(JTI));
    response.putAll(token.getAdditionalInformation());

    response.put(SUB, userId);/*ww  w.ja v  a2  s  .c o m*/
    if (null != clientScopes) {
        response.put(AUTHORITIES, AuthorityUtils.authorityListToSet(clientScopes));
    }

    response.put(OAuth2AccessToken.SCOPE, requestedScopes);
    response.put(CLIENT_ID, clientId);
    response.put(CID, clientId);
    response.put(AZP, clientId); // openId Connect

    if (null != grantType) {
        response.put(GRANT_TYPE, grantType);
    }
    if (!"client_credentials".equals(grantType)) {
        response.put(USER_ID, userId);
        response.put(USER_NAME, username == null ? userId : username);
        if (null != userEmail) {
            response.put(EMAIL, userEmail);
        }
    }

    if (StringUtils.hasText(revocableHashSignature)) {
        response.put(Claims.REVOCATION_SIGNATURE, revocableHashSignature);
    }

    response.put(IAT, issuedAtMillis / 1000);
    if (token.getExpiration() != null) {
        response.put(EXP, token.getExpiration().getTime() / 1000);
    }

    if (issuerId != null) {
        response.put(ISS, issuerId);
        response.put(ZONE_ID, zoneId);
    }

    response.put(AUD, resourceIds);

    return response;
}

From source file:net.mindengine.blogix.Blogix.java

private static void addUserCustomVariables(Map<String, Object> modelMap) {
    Map<String, String> properties = BlogixConfig.getConfig().getUserCustomProperties();
    modelMap.putAll(properties);
}

From source file:com.linkedin.pinot.controller.helix.core.UAutoRebalancer.java

public static boolean isTheSameMapping(Map oldMapping, Map nMapping) {
    if (oldMapping.size() != nMapping.size())
        return false;
    Map<String, Object> total = new HashedMap(oldMapping);
    total.putAll(nMapping);
    if (total.size() != oldMapping.size())
        return false;
    Set<Boolean> result = new HashSet<Boolean>();
    for (Object oKey : oldMapping.keySet()) {
        Object oValue = oldMapping.get(oKey);
        if (oValue instanceof String) {
            result.add(oValue.equals(nMapping.get(oValue)));
        } else if (oValue instanceof Map) {
            result.add(isTheSameMapping((Map) oValue, (Map) nMapping.get(oKey)));
        }//from   w w w.  j a v  a  2 s  . c  om
    }
    if (result.size() != 1)
        return false;
    return true;
}

From source file:com.asakusafw.yaess.bootstrap.Yaess.java

static Configuration parseConfiguration(String[] args) throws ParseException {
    assert args != null;
    LOG.debug("Analyzing YAESS bootstrap arguments: {}", Arrays.toString(args));

    ArgumentList argList = ArgumentList.parse(args);
    LOG.debug("Argument List: {}", argList);

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = parser.parse(OPTIONS, argList.getStandardAsArray());

    String profile = cmd.getOptionValue(OPT_PROFILE.getOpt());
    LOG.debug("Profile: {}", profile);
    String script = cmd.getOptionValue(OPT_SCRIPT.getOpt());
    LOG.debug("Script: {}", script);
    String batchId = cmd.getOptionValue(OPT_BATCH_ID.getOpt());
    LOG.debug("Batch ID: {}", batchId);
    String flowId = cmd.getOptionValue(OPT_FLOW_ID.getOpt());
    LOG.debug("Flow ID: {}", flowId);
    String executionId = cmd.getOptionValue(OPT_EXECUTION_ID.getOpt());
    LOG.debug("Execution ID: {}", executionId);
    String phaseName = cmd.getOptionValue(OPT_PHASE_NAME.getOpt());
    LOG.debug("Phase name: {}", phaseName);
    String plugins = cmd.getOptionValue(OPT_PLUGIN.getOpt());
    LOG.debug("Plug-ins: {}", plugins);
    Properties arguments = cmd.getOptionProperties(OPT_ARGUMENT.getOpt());
    LOG.debug("Execution arguments: {}", arguments);
    Properties variables = cmd.getOptionProperties(OPT_ENVIRONMENT_VARIABLE.getOpt());
    LOG.debug("Environment variables: {}", variables);
    Properties definitions = cmd.getOptionProperties(OPT_DEFINITION.getOpt());
    LOG.debug("YAESS feature definitions: {}", definitions);

    LOG.debug("Loading plugins: {}", plugins);
    List<File> pluginFiles = CommandLineUtil.parseFileList(plugins);
    ClassLoader loader = CommandLineUtil.buildPluginLoader(Yaess.class.getClassLoader(), pluginFiles);

    Configuration result = new Configuration();
    result.mode = computeMode(flowId, executionId, phaseName);

    LOG.debug("Loading profile: {}", profile);
    File file = new File(profile);
    file = findCustomProfile(file, definitions.getProperty(KEY_CUSTOM_PROFILE));
    try {/*  ww w . j  a va 2s .  c o m*/
        definitions.remove(KEY_CUSTOM_PROFILE);
        Map<String, String> env = new HashMap<>();
        env.putAll(System.getenv());
        env.putAll(toMap(variables));
        result.context = new ProfileContext(loader, new VariableResolver(env));
        Properties properties = CommandLineUtil.loadProperties(file);
        result.profile = YaessProfile.load(properties, result.context);
    } catch (Exception e) {
        YSLOG.error(e, "E01001", file.getPath());
        throw new IllegalArgumentException(MessageFormat.format("Invalid profile \"{0}\".", file), e);
    }

    LOG.debug("Loading script: {}", script);
    try {
        Properties properties = CommandLineUtil.loadProperties(new File(script));
        result.script = properties;
    } catch (Exception e) {
        YSLOG.error(e, "E01002", script);
        throw new IllegalArgumentException(MessageFormat.format("Invalid script \"{0}\".", script), e);
    }

    result.batchId = batchId;
    result.flowId = flowId;
    result.executionId = executionId;
    if (phaseName != null) {
        result.phase = ExecutionPhase.findFromSymbol(phaseName);
        if (result.phase == null) {
            throw new IllegalArgumentException(MessageFormat.format("Unknown phase name \"{0}\".", phaseName));
        }
    }

    result.arguments = toMap(arguments);
    result.definitions = toMap(definitions);
    result.extensions = CommandLineUtil.loadExtensions(loader, argList.getExtended());

    LOG.debug("Analyzed YAESS bootstrap arguments");
    return result;
}

From source file:com.tr8n.core.Utils.java

/**
 * Extends a map/*from w  w w .  j  a  v a 2  s  .  c  o  m*/
 * 
 * @param original
 * @param data
 * @return
 */
public static Map<String, Object> extendMap(Map<String, Object> original, Object... data) {
    Map<String, Object> map = new HashMap<String, Object>(original);
    map.putAll(buildMap(data));
    return map;
}

From source file:com.sirma.itt.cmf.integration.workflow.TransientNode.java

/**
 * Construct a transient node for an item yet to be created in the
 * Repository.//w  w w .  ja va 2  s  . c  om
 * 
 * This will apply any one-time initialisation required upon creation of the
 * node e.g. assignment of default values.
 *
 * @param registry the registry
 * @param typeDef The type definition this node will represent
 * @param name The name of the node
 * @param data The properties and associations this node will have
 * @return transient node
 */
public static TransientNode createNew(ServiceRegistry registry, TypeDefinition typeDef, String name,
        Map<QName, Serializable> data) {
    // build a complete anonymous type for the start task
    List<AspectDefinition> aspects = typeDef.getDefaultAspects();
    List<QName> aspectNames = new ArrayList<QName>(aspects.size());
    getMandatoryAspects(typeDef, aspectNames);
    ClassDefinition startTaskDef = registry.getDictionaryService().getAnonymousType(typeDef.getName(),
            aspectNames);

    // initialise start task values
    Map<QName, Serializable> startValues = new HashMap<QName, Serializable>();
    if (data != null) {
        startValues.putAll(data);
    }

    // apply default values
    Map<QName, PropertyDefinition> propertyDefs = startTaskDef.getProperties();
    for (Map.Entry<QName, PropertyDefinition> entry : propertyDefs.entrySet()) {
        String defaultValue = entry.getValue().getDefaultValue();
        if (defaultValue != null) {
            if (startValues.get(entry.getKey()) == null) {
                startValues.put(entry.getKey(), (Serializable) DefaultTypeConverter.INSTANCE
                        .convert(entry.getValue().getDataType(), defaultValue));
            }
        }
    }

    return new TransientNode(registry, typeDef.getName(), name, startValues);
}

From source file:org.jodconverter.cli.Convert.java

private static CliConverter createCliConverter(final CommandLine commandLine,
        final AbstractApplicationContext context, final OfficeManager officeManager,
        final DocumentFormatRegistry registry) {

    if (commandLine.hasOption(OPT_CONNECTION_URL.getOpt())) {
        return new CliConverter(
                OnlineConverter.builder().officeManager(officeManager).formatRegistry(registry).build());
    }//  w w  w.j a  v  a2s.c  o  m

    final LocalConverter.Builder builder = LocalConverter.builder().officeManager(officeManager)
            .formatRegistry(registry);

    // Specify custom load properties if required
    final Map<String, Object> loadProperties = buildProperties(
            commandLine.getOptionValues(OPT_LOAD_PROPERTIES.getOpt()));
    if (loadProperties != null) {
        // Ensure the default properties will be applied.
        final Map<String, Object> props = new HashMap<>(LocalConverter.DEFAULT_LOAD_PROPERTIES);
        props.putAll(loadProperties);
        builder.loadProperties(props);
    }

    // Specify custom store properties if required
    final Map<String, Object> storeProperties = buildProperties(
            commandLine.getOptionValues(OPT_STORE_PROPERTIES.getOpt()));
    if (storeProperties != null) {
        builder.storeProperties(storeProperties);
    }

    // Specify a filter chain if required
    final FilterChain filterChain = getFilterChain(context);
    if (filterChain != null) {
        builder.filterChain(filterChain);
    }
    return new CliConverter(builder.build());
}

From source file:com.alibaba.starter.utils.JStormHelper.java

/**
 * This function maybe not be useful in the future
 * @param conf//  w  w w .  j  a v  a  2  s .  com
 * @return
 */
@Deprecated
public static Map getFullConf(Map conf) {
    Map realConf = new HashMap();
    boolean isLocal = StormConfig.try_local_mode(conf);
    if (isLocal) {
        realConf.putAll(LocalCluster.getInstance().getLocalClusterMap().getConf());

    } else {
        realConf.putAll(Utils.readStormConfig());
    }
    realConf.putAll(conf);

    return realConf;
}

From source file:com.amazonaws.cbui.AmazonFPSCBUIPipeline.java

/**
 * Calculate String to Sign for SignatureVersion 1
 * /*from  w  w  w.ja  v  a 2s  .  c  o  m*/
 * @param parameters request parameters
 * @return String to Sign
 * @throws java.security.SignatureException
 */
private static String calculateStringToSignV1(Map<String, String> parameters) {
    StringBuilder data = new StringBuilder();
    Map<String, String> sorted = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
    sorted.putAll(parameters);
    Iterator<Map.Entry<String, String>> pairs = sorted.entrySet().iterator();
    while (pairs.hasNext()) {
        Map.Entry<String, String> pair = pairs.next();
        if (pair.getKey().equalsIgnoreCase(SIGNATURE_KEYNAME))
            continue;
        data.append(pair.getKey());
        data.append(pair.getValue());
    }
    return data.toString();
}