Example usage for java.util Map size

List of usage examples for java.util Map size

Introduction

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

Prototype

int size();

Source Link

Document

Returns the number of key-value mappings in this map.

Usage

From source file:com.l2jfree.gameserver.instancemanager.RaidPointsManager.java

@SuppressWarnings("unchecked")
public static Map<Integer, Integer> getRankList() {
    final Map<Integer, Integer> pointsByOwnerId = new HashMap<Integer, Integer>();

    for (int ownerId : _list.keySet()) {
        int totalPoints = getPointsByOwnerId(ownerId);
        if (totalPoints != 0)
            pointsByOwnerId.put(ownerId, totalPoints);
    }/*from  ww  w . j  a va 2s. c  om*/

    final Entry<Integer, Integer>[] entries = pointsByOwnerId.entrySet()
            .toArray(new Entry[pointsByOwnerId.size()]);

    Arrays.sort(entries, new Comparator<Map.Entry<Integer, Integer>>() {
        @Override
        public int compare(Map.Entry<Integer, Integer> entry, Map.Entry<Integer, Integer> entry1) {
            return entry.getValue().equals(entry1.getValue()) ? 0
                    : entry.getValue() < entry1.getValue() ? 1 : -1;
        }
    });

    Map<Integer, Integer> ranksByOwnerId = new HashMap<Integer, Integer>();
    int ranking = 1;
    for (Map.Entry<Integer, Integer> entry : entries)
        ranksByOwnerId.put(entry.getKey(), ranking++);

    return ranksByOwnerId;
}

From source file:com.nec.sydney.beans.exportroot.NSBeanUtil.java

public static void setProperties(Object bean, String[] valueArray) throws Exception {
    if (bean == null || valueArray == null || valueArray.length == 0) {
        return;/*from w w  w  . j a  va2s.  c o m*/
    }
    Map map = new TreeMap();
    for (int i = 0; i < valueArray.length; i++) {
        String keyAndValue = valueArray[i];
        if (keyAndValue == null || keyAndValue.indexOf(KEY_VALUE_SPLITER) == -1) {
            continue;
        } else {
            String[] tmpArray = valueArray[i].split(KEY_VALUE_SPLITER, 2);
            String key = tmpArray[0].trim();
            String value = tmpArray[1];
            map.put(key, value);
        }
    }
    if (map.size() > 0) {
        BeanUtils.populate(bean, map);
    }
    return;
}

From source file:com.sammyun.plugin.alipayWap.AlipayWapPlugin.java

/**
 * MAP??NameValuePair/*from   w  w  w .ja  v  a2s.co  m*/
 * 
 * @param properties MAP
 * @return NameValuePair
 */
private static NameValuePair[] generatNameValuePair(Map<String, Object> properties) {
    NameValuePair[] nameValuePair = new NameValuePair[properties.size()];
    int i = 0;
    for (Map.Entry<String, Object> entry : properties.entrySet()) {
        nameValuePair[i++] = new NameValuePair(entry.getKey(), entry.getValue().toString());
    }
    return nameValuePair;
}

From source file:com.discovery.darchrow.util.MapUtil.java

/**
 * ??map??map.//  w  w w  . j  a  v  a 2 s .co  m
 * 
 * <p style="color:green">
 *  {@link LinkedHashMap},??? ? <code>singleValueMap</code>??
 * </p>
 * 
 * <p>
 * ?? {@link #toSingleValueMap(Map)}
 * </p>
 * 
 * <h3>:</h3>
 * <blockquote>
 * 
 * <pre class="code">
 * Map{@code <String, String>} singleValueMap = new LinkedHashMap{@code <String, String>}();
 * 
 * singleValueMap.put("province", "??");
 * singleValueMap.put("city", "?");
 * 
 * LOGGER.info(JsonUtil.format(ParamUtil.toArrayValueMap(singleValueMap)));
 * </pre>
 * 
 * :
 * 
 * <pre class="code">
 * {
 * "province": ["??"],
 * "city": ["?"]
 * }
 * </pre>
 * 
 * </blockquote>
 *
 * @param <K>
 *            the key type
 * @param singleValueMap
 *            the name and value map
 * @return ? <code>singleValueMap</code> nullempty, {@link Collections#emptyMap()}<br>
 *         ? <code>singleValueMap</code> value?, <code>arrayValueMap</code>
 * @since 1.6.2
 */
public static <K> Map<K, String[]> toArrayValueMap(Map<K, String> singleValueMap) {
    if (Validator.isNullOrEmpty(singleValueMap)) {
        return Collections.emptyMap();
    }
    Map<K, String[]> arrayValueMap = newLinkedHashMap(singleValueMap.size());//????singleValueMap??
    for (Map.Entry<K, String> entry : singleValueMap.entrySet()) {
        arrayValueMap.put(entry.getKey(), ConvertUtil.toArray(entry.getValue()));//?Value???V,???Object
    }
    return arrayValueMap;
}

From source file:com.github.tteofili.p2h.Par2HierUtils.java

/**
 * perform PCA using SVD//  www .  j a va2  s  .  c  o  m
 *
 * @param weightTable the weights to scale
 * @param k the target vector dimensions
 * @return a weight table doc->reduced vector
 */
static Map<String, INDArray> svdPCA(Map<String, INDArray> weightTable, int k) {
    Map<String, INDArray> reducedVectors = new TreeMap<>();

    INDArray matrix = null;
    int i = 0;
    for (Map.Entry<String, INDArray> entry : weightTable.entrySet()) {
        INDArray vector = entry.getValue();
        if (matrix == null) {
            matrix = Nd4j.zeros(weightTable.size(), vector.columns());
        }
        matrix.putRow(i, vector);
        i++;
    }

    int j = 0;
    INDArray reducedMatrix = Nd4j.create(getTruncatedUT(matrix, k));
    for (Map.Entry<String, INDArray> entry : weightTable.entrySet()) {
        reducedVectors.put(entry.getKey(), reducedMatrix.getRow(j));
        j++;
    }

    return reducedVectors;
}

From source file:com.streamsets.pipeline.lib.jdbc.multithread.TableRuntimeContext.java

public static TableRuntimeContext createNextPartition(final TableRuntimeContext lastPartition) {
    if (!lastPartition.isPartitioned()) {
        throw new IllegalStateException("lastPartition TableRuntimeContext was not partitioned");
    }//w w  w .  java  2s.c om

    final Set<String> offsetColumns = lastPartition.getSourceTableContext().getOffsetColumns();
    final Map<String, String> startingPartitionOffsets = lastPartition.getStartingPartitionOffsets();

    if (startingPartitionOffsets.size() < offsetColumns.size()) {
        // we have not yet captured an offset for every offset columns
        if (LOG.isTraceEnabled()) {
            LOG.trace("Cannot create next partition after {} since we are missing values for offset columns {}",
                    lastPartition.getPartitionSequence(),
                    Sets.difference(offsetColumns, startingPartitionOffsets.keySet()));
        }
        return null;
    }

    final Map<String, String> nextStartingOffsets = new HashMap<>();
    final Map<String, String> nextMaxOffsets = new HashMap<>();

    final int newPartitionSequence = lastPartition.partitionSequence > 0 ? lastPartition.partitionSequence + 1
            : 1;

    lastPartition.startingPartitionOffsets.forEach((col, off) -> {
        String basedOnStartOffset = lastPartition.generateNextPartitionOffset(col, off);
        nextStartingOffsets.put(col, basedOnStartOffset);
    });

    nextStartingOffsets.forEach(
            (col, off) -> nextMaxOffsets.put(col, lastPartition.generateNextPartitionOffset(col, off)));

    final TableRuntimeContext nextPartition = new TableRuntimeContext(lastPartition.sourceTableContext,
            lastPartition.usingNonIncrementalLoad, lastPartition.partitioned, newPartitionSequence,
            nextStartingOffsets, nextMaxOffsets);

    return nextPartition;
}

From source file:acromusashi.stream.ml.clustering.kmeans.KmeansCalculator.java

/**
 * ?Counts??/*from w  w w.  j  a v a  2 s  . c  o  m*/
 * 
 * @param baseCounts Counts
 * @param targetCounts Counts
 * @param resultMapping ??
 * @return ?Counts
 */
protected static List<Long> mergeCounts(List<Long> baseCounts, List<Long> targetCounts,
        Map<Integer, Integer> resultMapping) {
    int countNum = resultMapping.size();
    List<Long> mergedCounts = new ArrayList<>(countNum);
    for (int count = 0; count < countNum; count++) {
        mergedCounts.add(0L);
    }

    for (Entry<Integer, Integer> resultEntry : resultMapping.entrySet()) {
        mergedCounts.set(resultEntry.getKey(),
                baseCounts.get(resultEntry.getKey()) + targetCounts.get(resultEntry.getValue()));
    }

    return mergedCounts;
}

From source file:com.liveneo.plat.utils.StringUtil.java

/**
 * Replaces all HTML-sensitive characters with their entity equivalents in
 * all string values in specified model. Some model values are skipped
 * untouched (their names are contained in exceptions set).
 * //w ww.  ja va  2s .co  m
 * @param model
 *            Map of pairs <code>variable -&gt; value</code>.
 * @return Map with encoded string values
 */
public static Map htmlEncodeModelWithExceptions(Map model, Set exceptions) {
    Map result = new HashMap(model.size());
    for (Iterator i = model.entrySet().iterator(); i.hasNext();) {
        Map.Entry entry = (Map.Entry) i.next();
        String key = (String) entry.getKey();
        Object value = (Object) entry.getValue();
        if (exceptions.contains(key)) {
            result.put(key, value);
        } else {
            if (value instanceof String) {
                result.put(key, htmlEncode((String) value));
            } else {
                result.put(key, value);
            }
        }
    }
    return result;
}

From source file:com.lxht.emos.data.cache.intf.HessianUtil.java

/**
 * ?map,??K,V = [k,v,k,v]/* w  w w.  j a va2s .  co m*/
 *
 * @param map
 * @return
 * @throws IOException
 */
public static final byte[][] mapToByteArray(Map<String, Serializable> map) throws IOException {
    if (map == null || map.isEmpty()) {
        throw new NullPointerException("mapToByteArray is null.");
    }

    byte[][] bytes = new byte[map.size() * 2][];

    int i = 0;
    for (Entry<String, Serializable> entry : map.entrySet()) {
        bytes[i] = entry.getKey().getBytes();
        bytes[i + 1] = serialize(entry.getValue());
        i = i + 2;
    }

    return bytes;

}

From source file:Main.java

/**
 * Creates a tag from the given string values. Can be used for creating html or xml tags.
 * /*from  ww  w .  ja  v a  2  s  . c o  m*/
 * @param tagname
 *            the tagname
 * @param value
 *            the value from the tag.
 * @param attributtes
 *            a map with the attributtes
 * @return the string
 */
public static String newTag(final String tagname, final String value, final Map<String, String> attributtes) {
    StringBuilder xmlTag = new StringBuilder();
    xmlTag.append("<").append(tagname);
    if (attributtes != null && !attributtes.isEmpty()) {
        xmlTag.append(" ");
        int count = 1;
        for (Map.Entry<String, String> attributte : attributtes.entrySet()) {
            xmlTag.append(attributte.getKey());
            xmlTag.append("=");
            xmlTag.append("\"").append(attributte.getValue()).append("\"");
            if (count != attributtes.size()) {
                xmlTag.append(" ");
            }
            count++;
        }
    }
    xmlTag.append(">");
    xmlTag.append(value);
    xmlTag.append("</").append(tagname).append(">");
    return xmlTag.toString();
}