Example usage for java.util HashMap putAll

List of usage examples for java.util HashMap putAll

Introduction

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

Prototype

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

Source Link

Document

Copies all of the mappings from the specified map to this map.

Usage

From source file:com.mobileglobe.android.customdialer.common.model.AccountTypeManager.java

/**
 * Return all usable {@link AccountType}s that support the "invite" feature from the
 * list of all potential invitable account types (retrieved from
 * {@link #getAllInvitableAccountTypes}). A usable invitable account type means:
 * (1) there is at least 1 raw contact in the database with that account type, and
 * (2) the app contributing the account type is not disabled.
 *
 * Warning: Don't use on the UI thread because this can scan the database.
 *//*from   w ww .j  a  va2  s . com*/
private Map<AccountTypeWithDataSet, AccountType> findUsableInvitableAccountTypes(Context context) {
    Map<AccountTypeWithDataSet, AccountType> allInvitables = getAllInvitableAccountTypes();
    if (allInvitables.isEmpty()) {
        return EMPTY_UNMODIFIABLE_ACCOUNT_TYPE_MAP;
    }

    final HashMap<AccountTypeWithDataSet, AccountType> result = Maps.newHashMap();
    result.putAll(allInvitables);

    final PackageManager packageManager = context.getPackageManager();
    for (AccountTypeWithDataSet accountTypeWithDataSet : allInvitables.keySet()) {
        AccountType accountType = allInvitables.get(accountTypeWithDataSet);

        // Make sure that account types don't come from apps that are disabled.
        Intent invitableIntent = MoreContactUtils.getInvitableIntent(accountType, SAMPLE_CONTACT_URI);
        if (invitableIntent == null) {
            result.remove(accountTypeWithDataSet);
            continue;
        }
        ResolveInfo resolveInfo = packageManager.resolveActivity(invitableIntent,
                PackageManager.MATCH_DEFAULT_ONLY);
        if (resolveInfo == null) {
            // If we can't find an activity to start for this intent, then there's no point in
            // showing this option to the user.
            result.remove(accountTypeWithDataSet);
            continue;
        }

        // Make sure that there is at least 1 raw contact with this account type. This check
        // is non-trivial and should not be done on the UI thread.
        if (!accountTypeWithDataSet.hasData(context)) {
            result.remove(accountTypeWithDataSet);
        }
    }

    return Collections.unmodifiableMap(result);
}

From source file:org.openvpms.report.jasper.AbstractJasperIMReport.java

/**
 * Generates a report.//from w ww . j  av  a2s.  co  m
 *
 * @param objects    the objects to report on
 * @param parameters a map of parameter names and their values, to pass to the report. May be {@code null}
 * @param fields     a map of additional field names and their values, to pass to the report. May be {@code null}
 * @return the report
 * @throws JRException for any error
 */
public JasperPrint report(Iterable<T> objects, Map<String, Object> parameters, Map<String, Object> fields)
        throws JRException {
    JRDataSource source = createDataSource(objects, fields);
    HashMap<String, Object> properties = new HashMap<String, Object>(getDefaultParameters());
    if (parameters != null) {
        properties.putAll(parameters);
    }
    properties.put("dataSource", source); // custom data source name, to avoid casting
    properties.put(JRParameter.REPORT_DATA_SOURCE, source);
    return JasperFillManager.fillReport(getReport(), properties, source);
}

From source file:com.thoughtworks.go.domain.materials.svn.SvnCommand.java

public HashMap<String, String> createUrlToRemoteUUIDMap(Set<SvnMaterial> svnMaterials) {
    HashMap<String, String> urlToUUIDMap = new HashMap<>();
    for (SvnMaterial svnMaterial : svnMaterials) {
        CommandLine command = svnExecutable().withArgs("info", "--xml");
        addCredentials(command, new StringArgument(svnMaterial.getUserName()),
                new PasswordArgument(svnMaterial.passwordForCommandLine()));
        final String queryUrl = svnMaterial.urlForCommandLine();
        command.withArg(queryUrl);// w  ww.j ava2 s.  co m
        ConsoleResult consoleResult = null;
        try {
            consoleResult = executeCommand(command);
            urlToUUIDMap.putAll(
                    svnLogXmlParser.parseInfoToGetUUID(consoleResult.outputAsString(), queryUrl, getBuilder()));
        } catch (RuntimeException e) {
            LOG.warn("Failed to map UUID to URL. SVN post-commit will not work for materials with URL {}",
                    queryUrl, e);
        }
    }
    return urlToUUIDMap;
}

From source file:org.shept.util.BeanUtilsExtended.java

/**
 * Find all occurrences of targetClass in targetObject.
 * Be careful. This stuff may be recursive !
 * Should be improved to prevent endless recursive loops.
 * //w ww.j a v a 2s  . co  m
 * @param
 * @return
 *
 * @param targetObject
 * @param targetClass
 * @param nestedPath
 * @return
 * @throws Exception 
 */
public static Map<String, ?> findNestedPaths(Object targetObject, Class<?> targetClass, String nestedPath,
        List<String> ignoreList, Set<Object> visited, int maxDepth) throws Exception {

    Assert.notNull(targetObject);
    Assert.notNull(targetClass);
    Assert.notNull(ignoreList);
    HashMap<String, Object> nestedPaths = new HashMap<String, Object>();
    if (maxDepth <= 0) {
        return nestedPaths;
    }

    nestedPath = (nestedPath == null ? "" : nestedPath);
    BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(targetObject);
    PropertyDescriptor[] props = bw.getPropertyDescriptors();

    for (PropertyDescriptor pd : props) {
        Class<?> clazz = pd.getPropertyType();
        if (clazz != null && !clazz.equals(Class.class) && !clazz.isAnnotation() && !clazz.isPrimitive()) {
            Object value = null;
            String pathName = pd.getName();
            if (!ignoreList.contains(pathName)) {
                try {
                    value = bw.getPropertyValue(pathName);
                } catch (Exception e) {
                } // ignore any exceptions here
                if (StringUtils.hasText(nestedPath)) {
                    pathName = nestedPath + PropertyAccessor.NESTED_PROPERTY_SEPARATOR + pathName;
                }
                // TODO break up this stuff into checking and excecution a la ReflectionUtils
                if (targetClass.isAssignableFrom(clazz)) {
                    nestedPaths.put(pathName, value);
                }
                // exclude objects already visited from further inspection to prevent circular references
                // unfortunately this stuff isn't fool proof as there are ConcurrentModificationExceptions
                // when adding objects to the visited list
                if (value != null && !isInstanceVisited(visited, value)) {
                    nestedPaths.putAll(
                            findNestedPaths(value, targetClass, pathName, ignoreList, visited, maxDepth - 1));
                }
            }
        }
    }
    return nestedPaths;
}

From source file:com.google.gwt.emultest.java.util.HashMapTest.java

public void testIsEmpty() {
    HashMap<String, String> srcMap = new HashMap<String, String>();
    checkEmptyHashMapAssumptions(srcMap);

    HashMap<String, String> dstMap = new HashMap<String, String>();
    checkEmptyHashMapAssumptions(dstMap);

    dstMap.putAll(srcMap);
    assertTrue(dstMap.isEmpty());/*from  w ww .j  a  v  a 2 s  .c  o m*/

    dstMap.put(KEY_KEY, VALUE_VAL);
    assertFalse(dstMap.isEmpty());

    dstMap.remove(KEY_KEY);
    assertTrue(dstMap.isEmpty());
    assertEquals(dstMap.size(), 0);
}

From source file:org.paxle.tools.ieporter.cm.impl.ConfigurationIEPorter.java

public Map<String, Document> exportConfigsAsDoc(Map<String, String> pidBundleLocationTupel) throws Exception {
    if (pidBundleLocationTupel == null)
        return null;

    // build result structure
    HashMap<String, Document> docs = new HashMap<String, Document>();
    for (Entry<String, String> entry : pidBundleLocationTupel.entrySet()) {
        String pid = entry.getKey();
        String bundleLocation = entry.getValue();

        // getting the configuration
        Configuration config = this.cm.getConfiguration(pid, bundleLocation);
        if (config != null) {
            Map<String, Document> doc = this.exportConfiguration(config);
            docs.putAll(doc);
        }//  w w  w.  j  a v a 2s  .co m
    }

    return docs;
}

From source file:com.impetus.ankush.common.domain.NodeMonitoring.java

/**
 * Method to get Service Status in its raw state i.e. without any check or update.
 * /*from w w  w.  j a  va2  s .  co m*/
 * @param technology
 * @return
 */
@Transient
public HashMap<String, Map<String, Boolean>> getTechnologyGroupedRawServiceStatus(String technology) {
    HashMap<String, Map<String, Boolean>> techServiceMap = new HashMap<String, Map<String, Boolean>>();
    HashMap<String, Map<String, Boolean>> serviceMap = new HashMap<String, Map<String, Boolean>>();
    byte[] techBytes = getTechnologyServiceBytes();
    if (techBytes == null) {
        return serviceMap;
    }

    // deserializing the data.
    techServiceMap = (HashMap<String, Map<String, Boolean>>) SerializationUtils.deserialize(techBytes);

    if (technology != null) {
        serviceMap.put(technology, techServiceMap.get(technology));
    } else {
        serviceMap.putAll(techServiceMap);
    }

    /*      
          if (technology == null) {
             Map agentStatus = new HashMap<String, Boolean>();
             agentStatus.put(Constant.Component.Name.AGENT, isAgentDown());
             serviceMap.put(Constant.Component.Name.AGENT, agentStatus);
          }
    */

    // return service status.
    return serviceMap;
}

From source file:org.wildfly.security.tool.VaultCommand.java

private HashMap<String, String> convert(String keyStoreURL, String vaultPassword, String encryptionDirectory,
        String salt, int iterationCount, String secretKeyAlias, String outputFile,
        Map<String, String> csAttributes, String csType, String csProvider, String csOtherProviders)
        throws Exception {

    final HashMap<String, String> vaultInitialOptions = new HashMap<>();

    if (encryptionDirectory == null || "".equals(encryptionDirectory)) {
        throw ElytronToolMessages.msg.undefinedEncryptionDirectory();
    }/*from  w  ww . j  ava 2 s .  com*/

    final File locationFile = new File(encryptionDirectory, "VAULT.dat");
    if (locationFile.exists()) {
        vaultInitialOptions.put("location", encryptionDirectory);
    } else {
        throw ElytronToolMessages.msg.vaultFileNotFound(encryptionDirectory);
    }

    if (secretKeyAlias == null || "".equals(secretKeyAlias)) {
        throw ElytronToolMessages.msg.undefinedAlias();
    }

    if (outputFile == null || "".equals(outputFile)) {
        throw ElytronToolMessages.msg.undefinedOutputLocation();
    }

    if (vaultPassword == null || "".equals(vaultPassword)) {
        throw ElytronToolMessages.msg.undefinedVaultPassword();
    }

    CredentialStore vaultCredentialStore = getInstance(VaultCredentialStore.VAULT_CREDENTIAL_STORE);
    vaultCredentialStore.initialize(vaultInitialOptions, getVaultCredentialStoreProtectionParameter(keyStoreURL,
            vaultPassword, salt, iterationCount, secretKeyAlias));

    final HashMap<String, String> convertedOptions = new HashMap<>();
    if (!Files.exists(Paths.get(outputFile))) {
        convertedOptions.put("location", outputFile);
    } else {
        throw ElytronToolMessages.msg.storageFileExists(outputFile);
    }
    convertedOptions.put("modifiable", Boolean.TRUE.toString());
    convertedOptions.put("create", Boolean.TRUE.toString());
    if (csAttributes != null) {
        convertedOptions.putAll(csAttributes);
    }
    convertedOptions.put("create", Boolean.TRUE.toString());
    if (csType == null || "".equals(csType)) {
        csType = KeyStoreCredentialStore.KEY_STORE_CREDENTIAL_STORE;
    }
    if (csType.equals(KeyStoreCredentialStore.KEY_STORE_CREDENTIAL_STORE)) {
        convertedOptions.put("keyStoreType", defaultKeyStoreType);
    }
    CredentialStore convertedCredentialStore;
    if (csProvider != null) {
        convertedCredentialStore = CredentialStore.getInstance(csType, csProvider,
                getProvidersSupplier(csProvider));
    } else {
        try {
            convertedCredentialStore = CredentialStore.getInstance(csType);
        } catch (NoSuchAlgorithmException e) {
            // fallback to load all possible providers
            convertedCredentialStore = CredentialStore.getInstance(csType, getProvidersSupplier(null));
        }
    }
    convertedCredentialStore.initialize(convertedOptions,
            getCredentialStoreProtectionParameter(vaultPassword, salt, iterationCount),
            getProvidersSupplier(csOtherProviders).get());
    for (String alias : vaultCredentialStore.getAliases()) {
        PasswordCredential credential = vaultCredentialStore.retrieve(alias, PasswordCredential.class);
        convertedCredentialStore.store(alias, credential);
    }
    convertedCredentialStore.flush();

    return convertedOptions;
}

From source file:com.google.gwt.emultest.java.util.HashMapTest.java

/**
 * Test method for 'java.util.HashMap.putAll(Map)'.
 */// www.  j av  a  2s.c om
public void testPutAll() {
    HashMap<String, String> srcMap = new HashMap<String, String>();
    checkEmptyHashMapAssumptions(srcMap);

    srcMap.put(KEY_1, VALUE_1);
    srcMap.put(KEY_2, VALUE_2);
    srcMap.put(KEY_3, VALUE_3);

    // Make sure that the data is copied correctly
    HashMap<String, String> dstMap = new HashMap<String, String>();
    checkEmptyHashMapAssumptions(dstMap);

    dstMap.putAll(srcMap);
    assertEquals(srcMap.size(), dstMap.size());
    assertTrue(dstMap.containsKey(KEY_1));
    assertTrue(dstMap.containsValue(VALUE_1));
    assertFalse(dstMap.containsKey(KEY_1.toUpperCase(Locale.ROOT)));
    assertFalse(dstMap.containsValue(VALUE_1.toUpperCase(Locale.ROOT)));

    assertTrue(dstMap.containsKey(KEY_2));
    assertTrue(dstMap.containsValue(VALUE_2));
    assertFalse(dstMap.containsKey(KEY_2.toUpperCase(Locale.ROOT)));
    assertFalse(dstMap.containsValue(VALUE_2.toUpperCase(Locale.ROOT)));

    assertTrue(dstMap.containsKey(KEY_3));
    assertTrue(dstMap.containsValue(VALUE_3));
    assertFalse(dstMap.containsKey(KEY_3.toUpperCase(Locale.ROOT)));
    assertFalse(dstMap.containsValue(VALUE_3.toUpperCase(Locale.ROOT)));

    // Check that an empty map does not blow away the contents of the
    // destination map
    HashMap<String, String> emptyMap = new HashMap<String, String>();
    checkEmptyHashMapAssumptions(emptyMap);
    dstMap.putAll(emptyMap);
    assertTrue(dstMap.size() == srcMap.size());

    // Check that put all overwrite any existing mapping in the destination map
    srcMap.put(KEY_1, VALUE_2);
    srcMap.put(KEY_2, VALUE_3);
    srcMap.put(KEY_3, VALUE_1);

    dstMap.putAll(srcMap);
    assertEquals(dstMap.size(), srcMap.size());
    assertEquals(dstMap.get(KEY_1), VALUE_2);
    assertEquals(dstMap.get(KEY_2), VALUE_3);
    assertEquals(dstMap.get(KEY_3), VALUE_1);

    // Check that a putAll does adds data but does not remove it

    srcMap.put(KEY_4, VALUE_4);
    dstMap.putAll(srcMap);
    assertEquals(dstMap.size(), srcMap.size());
    assertTrue(dstMap.containsKey(KEY_4));
    assertTrue(dstMap.containsValue(VALUE_4));
    assertEquals(dstMap.get(KEY_1), VALUE_2);
    assertEquals(dstMap.get(KEY_2), VALUE_3);
    assertEquals(dstMap.get(KEY_3), VALUE_1);
    assertEquals(dstMap.get(KEY_4), VALUE_4);

    dstMap.putAll(dstMap);
}

From source file:org.broadleafcommerce.core.pricing.service.FulfillmentPricingServiceImpl.java

@Override
public FulfillmentEstimationResponse estimateCostForFulfillmentGroup(FulfillmentGroup fulfillmentGroup,
        Set<FulfillmentOption> options) throws FulfillmentPriceException {
    FulfillmentEstimationResponse response = new FulfillmentEstimationResponse();
    HashMap<FulfillmentOption, Money> prices = new HashMap<FulfillmentOption, Money>();
    response.setFulfillmentOptionPrices(prices);
    for (FulfillmentPricingProvider provider : providers) {
        //Leave it up to the providers to determine if they can respond to a pricing estimate.  If they can't, or if one or more of the options that are passed in can't be responded
        //to, then the response from the pricing provider should not include the options that it could not respond to.
        try {/*  w ww  .j ava  2s  .  c om*/
            FulfillmentEstimationResponse processorResponse = provider
                    .estimateCostForFulfillmentGroup(fulfillmentGroup, options);
            if (processorResponse != null && processorResponse.getFulfillmentOptionPrices() != null
                    && processorResponse.getFulfillmentOptionPrices().size() > 0) {
                prices.putAll(processorResponse.getFulfillmentOptionPrices());
            }
        } catch (FulfillmentPriceException e) {
            //Shouldn't completely fail the rest of the estimation on a pricing exception. Another provider might still
            //be able to respond
            String errorMessage = "FulfillmentPriceException thrown when trying to estimate fulfillment costs from ";
            errorMessage += provider.getClass().getName();
            errorMessage += ". Underlying message was: " + e.getMessage();
            LOG.error(errorMessage);
        }
    }

    return response;
}