List of usage examples for java.util Map size
int size();
From source file:com.aol.advertising.qiao.util.ContextUtils.java
public static void resolvePropertyReferences(Map<String, PropertyValue> propsMap) throws BeansException, ClassNotFoundException { if (propsMap == null || propsMap.size() == 0) return;/* w ww . j a v a2 s.c o m*/ for (Entry<String, PropertyValue> entry : propsMap.entrySet()) { PropertyValue pv = entry.getValue(); if (pv.getType() == Type.IS_REF) { Object o = ContextUtils.loadClassById(pv.getValue()); if (o == null) { String err = "Unable to find bean id=" + pv.getValue(); logger.error(err); throw new BeanNotFoundException(err); } pv.setRefObject(o); } } }
From source file:com.netsteadfast.greenstep.base.model.SqlGenerateUtil.java
private static Map<String, Object> getNewFieldMap(Map<String, Object> fieldMap) throws Exception { Map<String, Object> newFieldMap = new HashMap<String, Object>(); if (fieldMap == null || fieldMap.size() < 1) { return newFieldMap; }// w w w . j a va2 s . com for (Map.Entry<String, Object> entry : fieldMap.entrySet()) { if (entry.getValue() != null) { newFieldMap.put(entry.getKey(), entry.getValue()); } } return newFieldMap; }
From source file:biz.netcentric.cq.tools.actool.installationhistory.impl.HistoryUtils.java
public static void setHistoryNodeProperties(final Node historyNode, AcInstallationHistoryPojo history) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {/*from w w w .jav a2 s . c o m*/ historyNode.setProperty(PROPERTY_INSTALLATION_DATE, history.getInstallationDate().toString()); historyNode.setProperty(PROPERTY_SUCCESS, history.isSuccess()); historyNode.setProperty(PROPERTY_EXECUTION_TIME, history.getExecutionTime()); String messageHistory = history.getVerboseMessageHistory(); // 16777216 bytes = ~ 16MB was the error in #145, assuming chars*2, hence 16777216 / 2 = 8MB, using 7MB to consider the BSON // overhead if (messageHistory.length() > (7 * 1024 * 1024)) { messageHistory = history.getMessageHistory(); // just use non-verbose history for this case } historyNode.setProperty(PROPERTY_MESSAGES, messageHistory); historyNode.setProperty(PROPERTY_TIMESTAMP, history.getInstallationDate().getTime()); historyNode.setProperty(PROPERTY_SLING_RESOURCE_TYPE, "/apps/netcentric/actool/components/historyRenderer"); Map<String, String> configFileContentsByName = history.getConfigFileContentsByName(); if (configFileContentsByName != null) { String commonPrefix = StringUtils.getCommonPrefix( configFileContentsByName.keySet().toArray(new String[configFileContentsByName.size()])); String crxPackageName = history.getCrxPackageName(); // for install hook case historyNode.setProperty(PROPERTY_INSTALLED_FROM, StringUtils.defaultString(crxPackageName) + commonPrefix); } }
From source file:com.cenrise.test.azkaban.PropsUtils.java
/** * @return the difference between oldProps and newProps. */// w ww. j ava 2 s .c om public static String getPropertyDiff(Props oldProps, Props newProps) { final StringBuilder builder = new StringBuilder(""); // oldProps can not be null during the below comparison process. if (oldProps == null) { oldProps = new Props(); } if (newProps == null) { newProps = new Props(); } final MapDifference<String, String> md = Maps.difference(toStringMap(oldProps, false), toStringMap(newProps, false)); final Map<String, String> newlyCreatedProperty = md.entriesOnlyOnRight(); if (newlyCreatedProperty != null && newlyCreatedProperty.size() > 0) { builder.append("Newly created Properties: "); newlyCreatedProperty.forEach((k, v) -> { builder.append("[ " + k + ", " + v + "], "); }); builder.append("\n"); } final Map<String, String> deletedProperty = md.entriesOnlyOnLeft(); if (deletedProperty != null && deletedProperty.size() > 0) { builder.append("Deleted Properties: "); deletedProperty.forEach((k, v) -> { builder.append("[ " + k + ", " + v + "], "); }); builder.append("\n"); } final Map<String, MapDifference.ValueDifference<String>> diffProperties = md.entriesDiffering(); if (diffProperties != null && diffProperties.size() > 0) { builder.append("Modified Properties: "); diffProperties.forEach((k, v) -> { builder.append("[ " + k + ", " + v.leftValue() + "-->" + v.rightValue() + "], "); }); } return builder.toString(); }
From source file:dk.statsbiblioteket.util.Logs.java
protected static void expand(StringWriter writer, Map map, int maxLength, int maxDepth) { writer.append(Integer.toString(map.size())); if (maxDepth == 0) { writer.append("(...)"); return;// ww w . j ava2s . c o m } int num = map.size() <= maxLength + 1 ? map.size() : Math.max(1, maxLength); writer.append("("); int counter = 0; for (Object oEntry : map.entrySet()) { Map.Entry entry = (Map.Entry) oEntry; writer.append("{"); expand(writer, entry.getKey(), maxLength, maxDepth - 1); writer.append(", "); expand(writer, entry.getValue(), maxLength, maxDepth - 1); writer.append("}"); if (counter++ < num - 1) { writer.append(", "); } else { break; } } if (num < map.size()) { writer.append(", ..."); } writer.append(")"); }
From source file:com.funambol.server.db.DataSourceContextHelper.java
/** * It reads all the datasource configurations, and for any of them, it creates/ * configures/binds a datasource using as jndiname the path of the configuration file. * <br/>//ww w .j a v a 2 s . c om * If simpleUsage is true, just the following configuration parameters are used: * <ul> * <li>url</li> * <li>username</li> * <li>password</li> * <li>driverClassName</li> * </ul> * @param simpleUsage if true, just url, username, password and driverClassName * are used. * @throws com.funambol.server.db.DataSourceConfigurationException if an error * occurs reading configurations */ private static void configureAndBindDataSources(boolean simpleUsage) throws DataSourceConfigurationException { dataSources = new HashMap(); // // 1. reading all configurations // Map<String, DataSourceConfiguration> configurations = DataSourceConfigurationHelper .getJDBCDataSourceConfigurations(); if (configurations == null || configurations.size() == 0) { // // no datasource to configure // if (logger.isTraceEnabled()) { logger.trace("No datasource to configure"); } return; } Iterator<String> itDataSourceName = configurations.keySet().iterator(); while (itDataSourceName.hasNext()) { String dataSourceName = itDataSourceName.next(); DataSourceConfiguration configuration = configurations.get(dataSourceName); DataSource ds = null; // // 2. creating the datasource // if (configuration != null) { try { Properties prop = null; if (simpleUsage) { prop = configuration.getBasicProperties(); } else { prop = configuration.getProperties(); } if (configuration instanceof RoutingDataSourceConfiguration) { // // A RoutingDataSource must be created. // ds = new RoutingDataSource((RoutingDataSourceConfiguration) configuration, simpleUsage); // // note that we can not call the RoutingDataSource.init and // RoutingDataSource.configure since they could use the jdbc/fnblcore that maybe // is not configured yet. See RoutingDataSource.getRoutedConnection. Those // methods are called there. // } else { // // No routing datasource // ds = BasicDataSourceFactory.createDataSource(prop); } } catch (Exception ex) { logger.error("Error creation the datasource 'jdbc/" + dataSourceName + "'", ex); continue; } } dataSources.put("jdbc/" + dataSourceName, ds); // // 3. binding datasource // try { bind(ds, "jdbc/" + dataSourceName); } catch (Exception e) { logger.error("Error binding the datasource 'jdbc/" + dataSourceName + "'", e); continue; } // // 4. registering the MBean // try { registerMBean(ds, "jdbc/" + dataSourceName); } catch (Exception e) { logger.error("Error registering MBeam for the datasource 'jdbc/" + dataSourceName + "'", e); continue; } } }
From source file:org.sinekartapdfa.util.JavaWebscriptTools.java
public static Response executeGetRequest(String url, Map<String, String> params, ConnectorService connectorService) { Connector connector = getConnector(connectorService); Map<String, String> header = new HashMap<String, String>(); Map<String, String> pp = new HashMap<String, String>(); if (params != null && params.size() > 0) { StringBuffer query = new StringBuffer(); if (url.indexOf('?') == -1) { query.append("?"); } else {/*from www.j av a 2s. co m*/ if (!url.endsWith("&")) { query.append("&"); } } for (String key : params.keySet()) { query.append(key); query.append("="); if (params.get(key) != null) query.append(URLEncoder.encode(params.get(key))); query.append("&"); } String q = query.toString(); q.substring(0, q.length() - 2); url = url + q; } ConnectorContext cc = new ConnectorContext(HttpMethod.GET, pp, header); return connector.call(url, cc); }
From source file:fi.hsl.parkandride.back.RequestLogDao.java
private static Map<RequestLogKey, Long> normalizeTimestamps(Map<RequestLogKey, Long> logCounts) { final Map<RequestLogKey, Long> normalized = logCounts.entrySet().stream() .map(entry -> Maps.immutableEntry(entry.getKey().roundTimestampDown(), entry.getValue())) .collect(toMapSummingCounts()); if (logCounts.size() != normalized.size()) { final List<DateTime> duplicatedTimestamps = collectDuplicateTimestamps(logCounts); logger.warn(/*www .jav a2 s . c o m*/ "Encountered entries with duplicated keys during timestamp normalization. The duplicated timestamps were summed. Duplicated timestamps: {}", duplicatedTimestamps); } return normalized; }
From source file:Main.java
/** * Join the two given maps to one by checking if one of the two maps already fulfills everything. Be aware that the * newly created collection is unmodifiable but will change if the underlying collections change! * * @param <K> The key type/*from w w w.j a v a 2 s . c o m*/ * @param <V> The value type * @param first The first {@link Map} to join * @param second The second {@link Map} to join * * @return A {@link Map} with the joined content (can be one of the given map if the other is empty or null) */ public static <K, V> Map<K, V> joinMapUnmodifiable(Map<K, V> first, Map<K, V> second) { if (first == null || first.isEmpty()) { if (second == null || second.isEmpty()) { return Collections.emptyMap(); } else { return Collections.unmodifiableMap(second); } } else if (second == null || second.isEmpty()) { return Collections.unmodifiableMap(first); } else { Map<K, V> temp = new LinkedHashMap<K, V>(first.size() + second.size()); temp.putAll(first); temp.putAll(second); return Collections.unmodifiableMap(temp); } }
From source file:com.offbynull.coroutines.instrumenter.testhelpers.TestUtils.java
/** * Opens up a ZIP resource, instruments the classes within, and returns a {@link URLClassLoader} object with access to those classes. * @param path path of zip resource//from w w w . jav a2s . c om * @return class loader able to access instrumented classes * @throws NullPointerException if any argument is {@code null} * @throws IOException if an IO error occurs */ public static URLClassLoader loadClassesInZipResourceAndInstrument(String path) throws IOException { Validate.notNull(path); // Load original class Map<String, byte[]> classContents = readZipFromResource(path); // Create JAR out of original classes so it can be found by the instrumenter List<JarEntry> originalJarEntries = new ArrayList<>(classContents.size()); for (Entry<String, byte[]> entry : classContents.entrySet()) { originalJarEntries.add(new JarEntry(entry.getKey(), entry.getValue())); } File originalJarFile = createJar(originalJarEntries.toArray(new JarEntry[0])); // Get classpath used to run this Java process and addIndividual the jar file we created to it (used by the instrumenter) List<File> classpath = getClasspath(); classpath.add(originalJarFile); // Instrument classes and write out new jar Instrumenter instrumenter = new Instrumenter(classpath); List<JarEntry> instrumentedJarEntries = new ArrayList<>(classContents.size()); for (Entry<String, byte[]> entry : classContents.entrySet()) { byte[] content = entry.getValue(); if (entry.getKey().endsWith(".class")) { content = instrumenter.instrument(content); } instrumentedJarEntries.add(new JarEntry(entry.getKey(), content)); } File instrumentedJarFile = createJar(instrumentedJarEntries.toArray(new JarEntry[0])); // Load up classloader with instrumented jar return URLClassLoader.newInstance(new URL[] { instrumentedJarFile.toURI().toURL() }, TestUtils.class.getClassLoader()); }