Example usage for java.util HashMap get

List of usage examples for java.util HashMap get

Introduction

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

Prototype

public V get(Object key) 

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:Main.java

public static void swapColors(BufferedImage img, Color... mapping) {
    int[] pixels = img.getRGB(0, 0, img.getWidth(), img.getHeight(), null, 0, img.getWidth());
    HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
    for (int i = 0; i < mapping.length / 2; i++) {
        map.put(mapping[2 * i].getRGB(), mapping[2 * i + 1].getRGB());
    }/*from   ww  w .  j a  v  a2s  .  co m*/
    for (int i = 0; i < pixels.length; i++) {
        if (map.containsKey(pixels[i]))
            pixels[i] = map.get(pixels[i]);
    }

    img.setRGB(0, 0, img.getWidth(), img.getHeight(), pixels, 0, img.getWidth());
}

From source file:com.collabnet.ccf.teamforge.TFAppHandler.java

public static TrackerFieldDO getTrackerFieldSoapDOForFlexField(HashMap<String, List<TrackerFieldDO>> fieldsMap,
        String fieldName) {/* w  w w .  j  a  v a 2 s.co m*/
    List<TrackerFieldDO> fieldsList = fieldsMap.get(fieldName);
    if (fieldsList != null) {
        if (fieldsList.size() == 1) {
            return fieldsList.get(0);
        } else if (fieldsList.size() > 1) {

            // FIXME What is a configurable field in this context?
            // TODO We are in trouble. We have a configurable field and a
            // flex field with the same name
        } else if (fieldsList.size() == 0) {
            // No way. This should never happen.
        }
    } else {
        log.warn("Field for " + fieldName + " does not exist.");
    }
    // TODO Should we return null here?
    return null;
}

From source file:com.morphoss.jumble.models.ModelParser.java

public static Collection<Category> readJsonData(String json) throws IOException, JSONException {

    JSONObject file = new JSONObject(json);
    JSONObject cats = file.getJSONObject("categories");
    JSONObject Words = file.getJSONObject("words");
    HashMap<Integer, Category> catMap = Category.getCategoriesFromJson(cats);

    HashMap<String, Word> words = Word.getWordFromJson(Words, catMap);

    HashMap<String, ArrayList<Localisation>> localisations = Localisation
            .getLocalisationFromJson(file.getJSONObject("localisations"));

    for (String cc : localisations.keySet()) {
        ArrayList<Localisation> locs = localisations.get(cc);
        for (Localisation loc : locs) {
            Word word = words.get(loc.getNameKey());
            if (word != null) {
                word.addLocalisation(cc, loc);
            } else {
                Log.e(TAG, "Unable to find original word with name key: " + loc.getNameKey());
            }/*w w  w.  j  a v a2 s  .c  o m*/
        }
    }

    return catMap.values();
}

From source file:net.firstpartners.nounit.utility.XmlUtil.java

/**
 * Search for Nodes within Jdom Document<BR>
 * @param inDocumentToSearch XML-JDOM Document  
 * @param  uniqueIdentifierName we can use to index the document (unique
 *    attribute like id or name present on the node we are searching for)
 * @param uniqueIdentifierToFind in the indexed document
 *//*from   w w w .j  a  va2s  . c o  m*/
public static Element findNode(Document inDocumentToSearch, String uniqueIdentifierName,
        String uniqueIdentifierToFind) {

    // index document                        
    HashMap index = getNodeIndex(inDocumentToSearch, uniqueIdentifierName);

    // Now get required element from index
    return (Element) index.get(uniqueIdentifierToFind);

}

From source file:Main.java

public static String getUrl(HashMap<String, String> params) {
    String url = null;/*www. jav  a  2s  .  c  o  m*/
    if (params != null) {
        Iterator<String> it = params.keySet().iterator();
        StringBuffer sb = null;
        while (it.hasNext()) {
            String key = it.next();
            String value = params.get(key);
            if (sb == null) {
                sb = new StringBuffer();
                sb.append("?");
            } else {
                sb.append("&");
            }
            sb.append(key);
            sb.append("=");
            sb.append(value);
        }
        url = sb.toString();
    }
    return url;
}

From source file:com.clustercontrol.accesscontrol.util.UserRoleCache.java

/**
 * ???ID??/*  w  w w. j a v  a2s . c  om*/
 * 
 * @param roleId ID
 * @return ID????
 */
public static List<String> getUserIdList(String roleId) {
    m_log.debug("getUserIdList() : roleId " + roleId);

    // ?????????????????????????
    // (?????????????????????????)
    HashMap<String, ArrayList<String>> cache = getRoleUserCache();
    return cache.get(roleId);
}

From source file:com.clustercontrol.accesscontrol.util.UserRoleCache.java

/**
 * ??ID??/*www . java 2 s .c  o m*/
 * 
 * @param userId ID
 * @return ID????
 */
public static List<String> getRoleIdList(String userId) {
    m_log.debug("getRoleIdList() : userId " + userId);

    // ?????????????????????????
    // (?????????????????????????)
    HashMap<String, ArrayList<String>> cache = getUserRoleCache();
    return cache.get(userId);
}

From source file:com.android.im.imps.ImpsPresenceUtils.java

/**
 * Extract the <code>Presence</code> from the <code>PrimitiveElement</code>
 * which contains the <code>PresenceSubList</code>.
 *
 * @param presenceListElem the <code>PrimitiveElement</code>
 * @return A new <code>Presence</code> containing the info extracted from the
 *          <code>PrimitiveElement</code>
 *//*w  ww  .  j  av  a2s  .c o  m*/
public static Presence extractPresence(PrimitiveElement presenceListElem, PresenceMapping mapping) {
    int status = extractPresenceStatus(presenceListElem, mapping);
    String statusText = extractStatusText(presenceListElem);
    byte[] avatarData = extractAvatarBytes(presenceListElem);
    String avatarType = extractAvatarType(presenceListElem);

    int clientType = Presence.CLIENT_TYPE_DEFAULT;
    HashMap<String, String> clientInfo = extractClientInfo(presenceListElem);
    if (ImpsConstants.PRESENCE_MOBILE_PHONE.equals(clientInfo.get(ImpsTags.ClientType))) {
        clientType = Presence.CLIENT_TYPE_MOBILE;
    }
    return new Presence(status, statusText, avatarData, avatarType, clientType);
}

From source file:com.collabnet.ccf.pi.sfee.v44.SFEEAppHandler.java

public static TrackerFieldSoapDO getTrackerFieldSoapDOForFlexField(
        HashMap<String, List<TrackerFieldSoapDO>> fieldsMap, String fieldName) {
    List<TrackerFieldSoapDO> fieldsList = fieldsMap.get(fieldName);
    if (fieldsList != null) {
        if (fieldsList.size() == 1) {
            return fieldsList.get(0);
        } else if (fieldsList.size() > 1) {

            // FIXME What is a configurable field in this context?
            // TODO We are in trouble. We have a configurable field and a
            // flex field with the same name
        } else if (fieldsList.size() == 0) {
            // No way. This should never happen.
        }//from   w  w w.j  a  v  a2 s  .  c  o  m
    } else {
        log.warn("Field for " + fieldName + " does not exist.");
    }
    // TODO Should we return null here?
    return null;
}

From source file:eu.hydrologis.jgrass.geonotes.util.ExifHandler.java

private static void dump(File imgFile) throws Exception {
    HashMap<String, String> readMetaData = ExifHandler.readMetaData(imgFile);
    DateTime creationDatetimeUtc = getCreationDatetimeUtc(readMetaData);
    String creationDate = readMetaData.get(TiffConstants.EXIF_TAG_CREATE_DATE.name);
    System.out.println(creationDate + " / " + creationDatetimeUtc);
    String lat = readMetaData.get(ExifHandler.GPS_LATITUDE_DEGREES_NORTH);
    String lon = readMetaData.get(ExifHandler.GPS_LONGITUDE_DEGREES_EAST);

    System.out.println("lat = " + lat + " / lon = " + lon);
}