Example usage for java.util Map clear

List of usage examples for java.util Map clear

Introduction

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

Prototype

void clear();

Source Link

Document

Removes all of the mappings from this map (optional operation).

Usage

From source file:com.fengduo.bee.search.utils.PinyinParser.java

/**
 * ???(??)/*from  ww w  . j  a  va2  s .com*/
 * 
 * @param args
 */
private static Set<String> parseTheChineseByObject(List<Map<String, Integer>> list) {
    Map<String, Integer> first = null; // ?,???
    // ????
    for (int i = 0; i < list.size(); i++) {
        // ???Map
        Map<String, Integer> temp = new Hashtable<String, Integer>();
        // first
        if (first != null) {
            // ????
            for (String s : first.keySet()) {
                for (String s1 : list.get(i).keySet()) {
                    String str = s + s1;
                    temp.put(str, 1);
                }
            }
            // ???
            if (temp != null && temp.size() > 0) {
                first.clear();
            }
        } else {
            for (String s : list.get(i).keySet()) {
                String str = s;
                temp.put(str, 1);
            }
        }
        // ???
        if (temp != null && temp.size() > 0) {
            first = temp;
        }
    }
    Set<String> result = new HashSet<String>();
    if (first != null) {
        // ????
        for (String str : first.keySet()) {
            result.add(str);
            if (result.size() >= 5) {
                break;
            }
        }
    }
    return result;
}

From source file:hoot.services.review.ReviewTestUtils.java

private static void populateOsmIdMappings(final Document changesetUploadResponse, final ElementType elementType,
        Map<Long, Long> mappings, final int size) throws XPathExpressionException {
    XPath xpath = XmlDocumentBuilder.createXPath();
    mappings.clear();

    //there aren't more than 100 elements of any type in the source file
    for (int i = 1; i < size + 1; i++) {
        final long oldId = -1 * i;
        final String newIdStr = xpath.evaluate("//osm/diffResult/" + elementType.toString().toLowerCase()
                + "[@old_id=\"" + oldId + "\"]/@new_id", changesetUploadResponse);
        if (StringUtils.trimToNull(newIdStr) != null) {
            final long newId = Long.parseLong(newIdStr);
            mappings.put(oldId, newId);/*from   w  w  w .j  av  a2  s . c  o m*/
        }
    }
}

From source file:de.j4velin.mapsmeasure.Util.java

/**
 * Replaces the current points on the map with the one from the provided
 * file// ww w .j  av  a 2 s  .  c o  m
 * 
 * @param f
 *            the file to read from
 * @param m
 *            the Map activity to add the new points to
 * @throws IOException
 */
static void loadFromFile(final Uri f, final Map m) throws IOException {
    List<LatLng> list = new LinkedList<LatLng>();
    BufferedReader in = new BufferedReader(new InputStreamReader(m.getContentResolver().openInputStream(f)));
    String line;
    String[] data;
    while ((line = in.readLine()) != null) {
        data = line.split(";");
        try {
            list.add(new LatLng(Double.parseDouble(data[0]), Double.parseDouble(data[1])));
        } catch (NumberFormatException nfe) {
            // should not happen when opening a valid file
            nfe.printStackTrace();
        } catch (ArrayIndexOutOfBoundsException aiabe) {
            // should not happen when opening a valid file
            aiabe.printStackTrace();
        }
    }
    in.close();
    m.clear();
    for (int i = 0; i < list.size(); i++) {
        m.addPoint(list.get(i));
    }
}

From source file:com.ntsync.shared.RequestGenerator.java

private static int readRowContainer(SecretKey key, List<RawContact> serverDirtyList,
        List<ContactGroup> serverGroupList, final byte[] response, final int contEndPos, int startPos,
        byte contType) throws UnsupportedEncodingException {
    int skippedRows = 0;
    String rowId = null;/*ww w . jav a  2 s .  c  o m*/
    Map<Byte, ByteBuffer> values = new HashMap<Byte, ByteBuffer>();
    int pos = startPos;

    while (pos < contEndPos && pos >= 0) {
        byte valueKey = response[pos];
        if (valueKey == ContactConstants.ROWID) {
            boolean ok = addRow(key, serverDirtyList, serverGroupList, contType, rowId, values);
            if (!ok) {
                skippedRows++;
            }
            values.clear();

            // Read RowId
            pos += 1;
            int rowIdLen = SyncDataHelper.readInt(response, pos);
            pos += ROWID_LEN;
            // UTF-8 is default on Android
            rowId = new String(response, pos, rowIdLen, SyncDataHelper.DEFAULT_CHARSET_NAME);
            pos += rowIdLen;
        } else if (valueKey == ContactConstants.SERVERROW_ID || valueKey == ContactConstants.MODIFIED
                || valueKey == ContactConstants.HASH || valueKey == ContactConstants.DELETED) {
            pos += 1;
            int valueLen = SyncDataHelper.readInt(response, pos);
            pos += VALUE_LEN;
            if (pos + valueLen <= contEndPos && valueLen >= 0) {
                values.put(valueKey, ByteBuffer.wrap(response, pos, valueLen));
            } else {
                LOG.warn(INVALID_BUFFER_MSG, pos, valueLen, contEndPos);
            }
            pos += valueLen;
        } else {
            // 1byte key, //16byte iv// //4 len
            pos += 1;

            int valueLen = SyncDataHelper.readInt(response, pos + CryptoHelper.IV_LEN);
            int bufLen = CryptoHelper.PREAMBLE_LEN + valueLen;
            if (pos + bufLen <= contEndPos && valueLen >= 0) {
                values.put(Byte.valueOf((byte) valueKey), ByteBuffer.wrap(response, pos, bufLen));
            } else {
                LOG.warn(INVALID_BUFFER_MSG, pos, valueLen, contEndPos);
            }
            pos += bufLen;
        }
    }

    boolean ok = addRow(key, serverDirtyList, serverGroupList, contType, rowId, values);
    if (!ok) {
        skippedRows++;
    }
    return skippedRows;
}

From source file:cc.unlimitedbladeworks.biz.admin.impl.AdminManagerImpl.java

@Override
public void increaseIndexClick() {
    Map<String, Object> map = new HashMap<>();
    map.clear();
    long now = new Date().getTime();
    map.put(BizKvDO.gmtUpdateStr, now);// w ww .ja  va 2s. c o m
    map.put(BizKvDO.keyStr, BizKvTags.index_click);
    map.put(BizKvDO.valueIntStr, 1);
    Integer result = bizKvDao.addValueIntByIdOrKey(map);
}

From source file:cc.unlimitedbladeworks.biz.admin.impl.AdminManagerImpl.java

@Override
public void refreshValues() {
    Map<String, Object> map = new HashMap<>();
    map.clear();
    List<BizKvDO> list = bizKvDao.queryAll(map);
    Map<String, BizKvDO> mapKv = new HashMap<>();
    for (BizKvDO bizKvDO : list) {
        mapKv.put(bizKvDO.getKey(), bizKvDO);
    }//from   w  w w .j  a va  2 s . c  om
    BizKvBO.copyBizKvMap(mapKv);
}

From source file:cc.unlimitedbladeworks.biz.admin.impl.AdminManagerImpl.java

@Override
public long getIndexClick() {
    Map<String, Object> map = new HashMap<>();
    map.clear();

    map.put(BizKvDO.keyStr, BizKvTags.index_click);

    List<BizKvDO> list = bizKvDao.queryAll(map);
    if (null != list && !list.isEmpty()) {
        return list.get(0).getValueInt();
    } else {/*from   w  ww. j a va2s  .co m*/
        return 0;
    }
}

From source file:com.fengduo.bee.commons.core.lang.BeanUtils.java

/**
 * ???//from   w  ww .  j  a va  2  s.c  o  m
 * 
 * @param f
 * @return
 */
public static Map<String, String> fieldEditable(Object oldObj, Object newObj) {
    Map<String, String> oldMap = getFieldValueMap(oldObj);
    Map<String, String> newMap = getFieldValueMap(newObj);

    Map<String, String> oldChangeMap = new HashMap<String, String>();
    Map<String, String> newChangeMap = new HashMap<String, String>();

    for (Entry<String, String> entry : oldMap.entrySet()) {
        String fieldKey = entry.getKey();
        if (StringUtils.equalsIgnoreCase(fieldKey, "gmtModified")
                || StringUtils.equalsIgnoreCase(fieldKey, "gmtCreate")) {
            continue;
        }
        String oldValue = entry.getValue();
        String newValue = newMap.get(fieldKey);
        if (!StringUtils.equalsIgnoreCase(oldValue, newValue)) {
            oldChangeMap.put(fieldKey, oldValue);
            newChangeMap.put(fieldKey, newValue);
        }
    }
    newMap.clear();
    newMap.put("oldString", new Gson().toJson(oldChangeMap));
    newMap.put("newString", new Gson().toJson(newChangeMap));
    return newMap;
}

From source file:be.kdg.repaircafemodel.service.impl.UserServiceImpl.java

/**
 * Clear all users./*from  w  w w  . j av a2 s.c  o  m*/
 */
@Override
public void removeAllUsers() {
    final Map<String, User> users = userDAO.getUsers();
    users.clear();
}

From source file:com.alibaba.napoli.metamorphosis.utils.DiamondUtils.java

/** ??topic?(?topic) */
public static void getPartitions(final Properties properties, final Map<String, List<Partition>> ret) {
    log.info("??");
    final Map<String, List<Partition>> map = new HashMap<String, List<Partition>>();
    if (properties != null) {
        for (final Map.Entry<Object, Object> entry : properties.entrySet()) {
            final String key = (String) entry.getKey();

            if (key != null && key.startsWith("topic.num.")) {
                // key?topic
                final String topic = key.substring("topic.num.".length());
                // value?brokerId0:num0;brokerId1:num1;...
                final String value = (String) entry.getValue();
                final List<Partition> partitions = parsePartitions(value);
                if (partitions != null && !partitions.isEmpty()) {
                    map.put(topic, partitions);
                }//from www .  j a v  a  2  s.  c  o  m
            }
        }
        ret.clear();
        ret.putAll(map);
        if (!ret.isEmpty()) {
            log.info("?: " + map);
        } else {
            log.info("empty partitionsNum info");
        }
    } else {
        log.warn("Null partitionsNum config");
    }

}