Example usage for java.util HashMap put

List of usage examples for java.util HashMap put

Introduction

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

Prototype

public V put(K key, V value) 

Source Link

Document

Associates the specified value with the specified key in this map.

Usage

From source file:Main.java

public static ArrayList<HashMap<String, String>> cursorToHashMap(Cursor cursor) {

    if (cursor != null) {
        int cursorCount = cursor.getCount();
        int columnCount;
        ArrayList<HashMap<String, String>> cursorData = new ArrayList<HashMap<String, String>>();
        HashMap<String, String> rowHashMap;
        for (int i = 0; i < cursorCount; i++) {
            cursor.moveToPosition(i);//from   w w w  . j av  a 2  s .  c  o m
            rowHashMap = new HashMap<String, String>();
            columnCount = cursor.getColumnCount();
            for (int j = 0; j < columnCount; j++) {
                rowHashMap.put(cursor.getColumnName(j), cursor.getString(j));
            }
            cursorData.add(rowHashMap);
        }
        cursor.close();

        return cursorData;
    } else {
        return null;
    }
}

From source file:com.clustercontrol.maintenance.factory.HinemosPropertyInfoCache.java

private static HashMap<String, HinemosPropertyInfo> createHinemosPropertyInfoMap() {
    HashMap<String, HinemosPropertyInfo> infoMap = new HashMap<String, HinemosPropertyInfo>();
    List<HinemosPropertyInfo> entities = QueryUtil.getAllHinemosProperty_None();
    for (HinemosPropertyInfo entity : entities) {
        infoMap.put(entity.getKey(), entity);
    }//from w  ww . j  ava  2 s.c o m
    return infoMap;
}

From source file:com.scaniatv.LangFileUpdater.java

/**
 * Method that gets the ID from the custom and default lang file, and adds 
 * missing lang IDs to the custom one, plus returns the lang ID and matches in a HashMap.
 * /*from  w w w.j a v a  2 s  .co  m*/
 * @param defaultLang
 * @param customLang
 * @return 
 */
private static HashMap<String, String> getCustomAndDefaultLangMap(String defaultLang, String customLang) {
    // Create a new patter that will match if the default lang ID is also in the custom one.
    final Pattern pattern = Pattern.compile(
            "^\\$\\.lang\\.register\\((\\'|\\\")([a-zA-Z0-9,.-]+)(\\'|\\\")\\,\\s(\\'|\\\")(.*)(\\'|\\\")\\);",
            Pattern.MULTILINE);

    // Get all matches for the default lang.
    final Matcher m1 = pattern.matcher(defaultLang);
    final HashMap<String, String> defaultMatches = new HashMap<>();
    while (m1.find()) {
        defaultMatches.put(m1.group(2), m1.group(5));
    }

    // Get all matches for the custom lang.
    final Matcher m2 = pattern.matcher(customLang);
    final HashMap<String, String> customMatches = new HashMap<>();
    while (m2.find()) {
        customMatches.put(m2.group(2), m2.group(5));
    }

    // Check if any is missing in the custom one.
    defaultMatches.forEach((String key, String value) -> {
        if (!customMatches.containsKey(key)) {
            customMatches.put(key, value);
        }
    });

    return customMatches;
}

From source file:info.aamulumi.tomate.APIConnection.java

/**
 * Send a request to create a user/*w ww  .j  a v a2  s . c o m*/
 *
 * @param firstName - firstName of user
 * @param lastName  - lastName of user
 * @param email     - email of user
 * @return the created user
 */
public static User createUser(String firstName, String lastName, String email) {
    HashMap<String, String> params = new HashMap<>(3);
    params.put("firstName", firstName);
    params.put("lastName", lastName);
    params.put("email", email);

    return APIConnection.createItem(urlUsers, "parseUser", null, params);
}

From source file:mobile.vo.rns.ServiceDetailVO.java

public static ServiceDetailVO create(Service po) {
    ObjectMapper objectMapper = JackJsonUtil.getMapperInstance(false);
    ServiceDetailVO vo = new ServiceDetailVO();

    vo.setId(po.getId());/*from w  w  w .  jav a 2 s .com*/

    SkillTag industry = po.getIndustry();
    if (null != industry) {
        vo.setIndustryId(industry.getId());
        vo.setIndustryName(industry.getTagName());
    }

    vo.setTitle(po.getTitle());
    vo.setInfo(po.getInfo());

    if (null == po.getPrice()) {
        vo.setPrice("-1");// -1 - ?
    } else {
        vo.setPrice(new BigDecimal(po.getPrice()).setScale(1, BigDecimal.ROUND_HALF_UP).toString());
    }

    vo.setCreateDate(new DateTime(po.getCreateDate()).toString("yyyy-MM-dd HH:mm:ss"));

    vo.setCoverUrl(Assets.at(po.getCoverUrl()));

    if (StringUtils.isNotBlank(po.getTags())) {
        try {
            @SuppressWarnings("unchecked")
            List<String> readValue = objectMapper.readValue(po.getTags(), List.class);
            vo.setTags(readValue);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    Iterator<AttachOfService> iterator = po.getCaseAttachs().iterator();
    while (iterator.hasNext()) {
        AttachOfService attachOfService = iterator.next();
        HashMap<String, Object> pair = new HashMap<String, Object>();
        pair.put("attachId", attachOfService.id);
        pair.put("url", Assets.at(attachOfService.path));
        vo.getAttachs().add(pair);
    }

    Expert ownerExpert = po.getOwner().getExperts().iterator().next();
    vo.setOwner(User.create(ownerExpert));

    vo.setCommentInfo(CommentInfo.create(po));

    ServiceComment latestComment = ServiceComment.getLatestCommentByServiceId(po.getId());
    vo.setLatestComment(CommentItem.create(latestComment));

    return vo;
}

From source file:org.kitodo.data.elasticsearch.MockEntity.java

public static HashMap<Integer, HttpEntity> createEntities() {
    HashMap<Integer, HttpEntity> documents = new HashMap<>();

    String jsonString = "{\"title\":\"Batch1\",\"type\":\"LOGISTIC\",\"amount\":2,\"processes\":[{\"id\":\"1\"},{\"id\":\"2\"}]}";
    HttpEntity entity = new NStringEntity(jsonString, ContentType.APPLICATION_JSON);
    documents.put(1, entity);

    jsonString = "{\"title\":\"Sort\",\"type\":\"null\",\"amount\":4,\"processes\":[]}";
    entity = new NStringEntity(jsonString, ContentType.APPLICATION_JSON);
    documents.put(2, entity);/*from w  w  w  .  jav  a  2  s . co m*/

    jsonString = "{\"title\":\"Batch2\",\"type\":\"null\",\"amount\":0,\"processes\":[]}";
    entity = new NStringEntity(jsonString, ContentType.APPLICATION_JSON);
    documents.put(3, entity);

    jsonString = "{\"title\":\"Order\",\"type\":\"null\",\"amount\":2,\"processes\":[]}";
    entity = new NStringEntity(jsonString, ContentType.APPLICATION_JSON);
    documents.put(4, entity);

    return documents;
}

From source file:com.gst.integrationtests.common.CenterHelper.java

public static String assignStaffAsJSON(final Long staffId) {
    final HashMap<String, Object> map = new HashMap<>();
    map.put("staffId", staffId);
    System.out.println("map : " + map);
    return new Gson().toJson(map);
}

From source file:com.gst.integrationtests.common.CenterHelper.java

public static String unassignStaffAsJSON(final Long staffId) {
    final HashMap<String, Object> map = new HashMap<>();
    map.put("staffId", staffId);
    System.out.println("map : " + map);
    return new Gson().toJson(map);
}

From source file:com.caris.oscarexchange4j.proxy.PreviewCoverage.java

/**
 * Verify some expected parameters are present, set them if not so we will
 * have a happy request./*from ww w.  j  av  a2 s  .  c o  m*/
 * 
 * @param parameterMap
 *            The parameter map.
 */
private static void verifyParameters(HashMap<String, String> parameterMap) {
    if (!parameterMap.containsKey(PreviewCoverage.REQUEST)) {
        parameterMap.put(PreviewCoverage.REQUEST, "GetCoverage");
    }

    parameterMap.put(STORE, STORE_VALUE);
    parameterMap.put(GRIDTYPE, EXPECTED_GRIDTYPE);
    parameterMap.put(SERVICE, SERVICE_VALUE);
    parameterMap.put(FORMAT, EXPECTED_FORMAT);

    if (parameterMap.containsKey(BOUNDINGBOX) && parameterMap.containsKey(GRIDBASECRS)) {
        if (!parameterMap.get(BOUNDINGBOX).endsWith("," + parameterMap.get(GRIDBASECRS))) {
            String bbox = parameterMap.get(BOUNDINGBOX) + "," + parameterMap.get(GRIDBASECRS);
            parameterMap.put(BOUNDINGBOX, bbox);
        }
    }

}

From source file:com.gmail.frogocomics.schematic.BiomeWorldV2Object.java

public static BiomeWorldV2Object load(File file) throws IOException {

    BufferedReader settingsReader;

    if (!file.exists()) {
        throw new FileNotFoundException();
    }//from ww w .  j  a  va 2 s  .com
    settingsReader = new BufferedReader(new FileReader(file));
    int lineNumber = 0;
    String thisLine;
    ArrayList<BiomeWorldObjectBlock> bo2Blocks = new ArrayList<>();

    while ((thisLine = settingsReader.readLine()) != null) {
        lineNumber++;
        if (Pattern.compile("[0-9]").matcher(thisLine.substring(0, 1)).matches()
                || thisLine.substring(0, 1).equalsIgnoreCase("-")) {
            //Example: -1,-1,5:18.4
            // x,z,y:id.data
            String[] location = thisLine.split(":")[0].split(",");
            String[] block = thisLine.split(":")[1].split("\\.");
            bo2Blocks.add(new BiomeWorldObjectBlock(Integer.parseInt(location[0]),
                    Integer.parseInt(location[2]), Integer.parseInt(location[1]), Short.parseShort(block[0]),
                    Byte.parseByte(block[1])));
        }
    }

    ArrayList<Integer> maxXMap = new ArrayList<>();
    ArrayList<Integer> maxYMap = new ArrayList<>();
    ArrayList<Integer> maxZMap = new ArrayList<>();
    for (BiomeWorldObjectBlock bo2 : bo2Blocks) {
        maxXMap.add(bo2.getX());
        maxYMap.add(bo2.getY());
        maxZMap.add(bo2.getZ());
    }

    int maxX = Collections.max(maxXMap);
    int maxY = Collections.max(maxYMap);
    int maxZ = Collections.max(maxZMap);
    int minX = Collections.min(maxXMap);
    int minY = Collections.min(maxYMap);
    int minZ = Collections.min(maxZMap);
    int differenceX = maxX - minX + 1;
    int differenceY = maxY - minY + 1;
    int differenceZ = maxZ - minZ + 1;

    HashMap<Integer, Set<BiomeWorldObjectBlock>> blocks = new HashMap<>();
    for (int i = 0; i < differenceY + 1; i++) {
        blocks.put(i, new HashSet<>());
    }

    for (BiomeWorldObjectBlock bo2 : bo2Blocks) {
        Set<BiomeWorldObjectBlock> a = blocks.get(bo2.getY() - minY);
        a.add(bo2);
        blocks.replace(bo2.getY(), a);
    }

    //System.out.println(differenceX + " " + differenceZ);
    SliceStack schematic = new SliceStack(differenceY, differenceX, differenceZ);

    for (Map.Entry<Integer, Set<BiomeWorldObjectBlock>> next : blocks.entrySet()) {
        Slice slice = new Slice(differenceX, differenceZ);
        for (BiomeWorldObjectBlock block : next.getValue()) {
            //System.out.println("Added block at " + String.valueOf(block.getX() - minX) + "," + String.valueOf(block.getZ() - minZ));
            slice.setBlock(block.getBlock(), block.getX() - minX, block.getZ() - minZ);
        }
        schematic.addSlice(slice);
    }
    //System.out.println(schematic.toString());

    return new BiomeWorldV2Object(schematic, FilenameUtils.getBaseName(file.getAbsolutePath()));
}