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:bammerbom.ultimatecore.bukkit.resources.utils.UuidUtil.java

public static void loadPlayers() {
    File directory = new File(r.getUC().getDataFolder() + File.separator + "Players");
    if (!directory.exists()) {
        directory.mkdirs();//w  w  w  .ja  v  a 2  s  .c o  m
    }
    ArrayList<UUID> request = null;
    for (OfflinePlayer p : r.getOfflinePlayers()) {
        if (p.getUniqueId() == null) {
            continue;
        }
        final File file = new File(r.getUC().getDataFolder() + File.separator + "Players" + File.separator
                + p.getUniqueId() + ".yml");
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {
                ErrorLogger.log(e, "Failed to create new file for " + p.getUniqueId());
            }
        }
        Config conf = new Config(file);
        if (p.getName() == null) {
            if (!conf.contains("name")) {
                if (request == null) {
                    request = new ArrayList<>();
                }
                request.add(p.getUniqueId());
            }
        } else {
            if (!conf.contains("name")) {
                conf.set("name", p.getName());
                conf.save();
                if (!conf.contains("names")) {
                    ArrayList<String> names = new ArrayList<>();
                    Calendar timeCal = Calendar.getInstance();
                    timeCal.setTimeInMillis(System.currentTimeMillis());
                    String date = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(timeCal.getTime());
                    names.add(p.getName() + " - " + date);
                    conf.set("names", names);
                    conf.save();
                }
            } else {
                if (!conf.contains("names")) {
                    ArrayList<String> names = new ArrayList<>();
                    Calendar timeCal = Calendar.getInstance();
                    timeCal.setTimeInMillis(System.currentTimeMillis());
                    String date = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(timeCal.getTime());
                    names.add(p.getName() + " - " + date);
                    conf.set("names", names);
                    conf.save();
                }
                if (!conf.getString("name").equals(p.getName())) {
                    String oldname = conf.getString("name");
                    Calendar timeCal = Calendar.getInstance();
                    timeCal.setTimeInMillis(System.currentTimeMillis());
                    String date = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(timeCal.getTime());
                    List<String> names = conf.getStringList("names");
                    if (names == null) {
                        names = new ArrayList<>();
                    }
                    names.add(p.getName() + " - " + date);
                    conf.set("names", names);
                    conf.set("name", p.getName());
                    if (p.isOnline()) {
                        r.sendMes((CommandSender) p, "nameChanged", "%Oldname", oldname, "%Newname",
                                p.getName());
                    } else {
                        conf.set("oldname", oldname);
                    }
                    conf.save();
                }
            }
        }
    }
    if (request != null) {
        final ArrayList<UUID> req = request;
        try {
            r.log("Starting playerfile update...");
            HashMap<UUID, String> s = new UuidToName(req).call();
            for (UUID u : s.keySet()) {
                String n = s.get(u);
                File f = new File(
                        r.getUC().getDataFolder() + File.separator + "Players" + File.separator + u + ".yml");
                Config conf = new Config(f);
                conf.set("name", n);
                conf.save();
                //
                if (!conf.contains("names")) {
                    ArrayList<String> names = new ArrayList<>();
                    Calendar timeCal = Calendar.getInstance();
                    timeCal.setTimeInMillis(System.currentTimeMillis());
                    String date = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(timeCal.getTime());
                    names.add(n + " - " + date);
                    conf.set("names", names);
                    conf.save();
                }
                //
            }
            r.log("Playerfile update complete.");
        } catch (Exception e) {
            ErrorLogger.log(e, "Failed to convert uuids to names.");
        }
    }

}

From source file:bammerbom.ultimatecore.spongeapi.resources.utils.UuidUtil.java

public static void loadPlayers() {
    File directory = new File(r.getUC().getDataFolder() + File.separator + "Players");
    if (!directory.exists()) {
        directory.mkdirs();/*from   w ww  .ja  v a  2s.  c o m*/
    }
    ArrayList<UUID> request = null;
    for (User p : r.getOfflinePlayers()) {
        if (p.getUniqueId() == null) {
            continue;
        }
        final File file = new File(r.getUC().getDataFolder() + File.separator + "Players" + File.separator
                + p.getUniqueId() + ".yml");
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {
                ErrorLogger.log(e, "Failed to create new file for " + p.getUniqueId());
            }
        }
        Config conf = new Config(file);
        if (p.getName() == null) {
            if (!conf.contains("name")) {
                if (request == null) {
                    request = new ArrayList<>();
                }
                request.add(p.getUniqueId());
            }
        } else {
            if (!conf.contains("name")) {
                conf.set("name", p.getName());
                conf.save();
                if (!conf.contains("names")) {
                    ArrayList<String> names = new ArrayList<>();
                    Calendar timeCal = Calendar.getInstance();
                    timeCal.setTimeInMillis(System.currentTimeMillis());
                    String date = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(timeCal.getTime());
                    names.add(p.getName() + " - " + date);
                    conf.set("names", names);
                    conf.save();
                }
            } else {
                if (!conf.contains("names")) {
                    ArrayList<String> names = new ArrayList<>();
                    Calendar timeCal = Calendar.getInstance();
                    timeCal.setTimeInMillis(System.currentTimeMillis());
                    String date = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(timeCal.getTime());
                    names.add(p.getName() + " - " + date);
                    conf.set("names", names);
                    conf.save();
                }
                if (!conf.getString("name").equals(p.getName())) {
                    String oldname = conf.getString("name");
                    Calendar timeCal = Calendar.getInstance();
                    timeCal.setTimeInMillis(System.currentTimeMillis());
                    String date = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(timeCal.getTime());
                    List<String> names = conf.getStringList("names");
                    if (names == null) {
                        names = new ArrayList<>();
                    }
                    names.add(p.getName() + " - " + date);
                    conf.set("names", names);
                    conf.set("name", p.getName());
                    if (p.isOnline()) {
                        r.sendMes((CommandSource) p, "nameChanged", "%Oldname", oldname, "%Newname",
                                p.getName());
                    } else {
                        conf.set("oldname", oldname);
                    }
                    conf.save();
                }
            }
        }
    }
    if (request != null) {
        final ArrayList<UUID> req = request;
        try {
            r.log("Starting playerfile update...");
            HashMap<UUID, String> s = new UuidToName(req).call();
            for (UUID u : s.keySet()) {
                String n = s.get(u);
                File f = new File(
                        r.getUC().getDataFolder() + File.separator + "Players" + File.separator + u + ".yml");
                Config conf = new Config(f);
                conf.set("name", n);
                conf.save();
                //
                if (!conf.contains("names")) {
                    ArrayList<String> names = new ArrayList<>();
                    Calendar timeCal = Calendar.getInstance();
                    timeCal.setTimeInMillis(System.currentTimeMillis());
                    String date = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(timeCal.getTime());
                    names.add(n + " - " + date);
                    conf.set("names", names);
                    conf.save();
                }
                //
            }
            r.log("Playerfile update complete.");
        } catch (Exception e) {
            ErrorLogger.log(e, "Failed to convert uuids to names.");
        }
    }

}

From source file:org.samjoey.graphing.GraphUtility.java

public static void createGraphs(LinkedList<Game> games) {
    HashMap<String, XYSeriesCollection> datasets = new HashMap<>();
    for (Game game : games) {
        for (String key : game.getVarData().keySet()) {
            if (datasets.containsKey(key)) {
                try {
                    datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
                } catch (Exception e) {
                }/*from ww  w.j a va2s.  c o  m*/
            } else {
                datasets.put(key, new XYSeriesCollection());
                datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
            }
        }
    }

    for (String key : datasets.keySet()) {
        JFrame f = new JFrame();
        JFreeChart chart = ChartFactory.createXYLineChart(key, // chart title
                "X", // x axis label
                "Y", // y axis label
                datasets.get(key), // data
                PlotOrientation.VERTICAL, false, // include legend
                true, // tooltips
                false // urls
        );
        XYPlot plot = chart.getXYPlot();
        XYItemRenderer rend = plot.getRenderer();
        for (int i = 0; i < games.size(); i++) {
            Game g = games.get(i);
            if (g.getWinner() == 1) {
                rend.setSeriesPaint(i, Color.RED);
            }
            if (g.getWinner() == 2) {
                rend.setSeriesPaint(i, Color.BLACK);
            }
            if (g.getWinner() == 0) {
                rend.setSeriesPaint(i, Color.PINK);
            }
        }
        ChartPanel chartPanel = new ChartPanel(chart);
        f.setContentPane(chartPanel);
        f.pack();
        RefineryUtilities.centerFrameOnScreen(f);
        f.setVisible(true);
    }
}

From source file:com.cloudera.kitten.appmaster.util.HDFSFileFinder.java

public static Map<String, Long> getNumBytesOfGlobHeldByDatanodes(Path p, Configuration conf)
        throws IOException {
    FileSystem fs = p.getFileSystem(conf);

    HashMap<String, Long> bytesHeld = Maps.newHashMap();
    for (FileStatus f : fs.globStatus(p)) {
        BlockLocation[] bls = fs.getFileBlockLocations(p, 0, f.getLen());
        if (bls.length > 0) {
            for (BlockLocation bl : bls) {
                long l = bl.getLength();
                for (String name : bl.getNames()) {
                    if (bytesHeld.containsKey(name))
                        bytesHeld.put(name, bytesHeld.get(name) + l);
                    else
                        bytesHeld.put(name, l);
                }/* w  w w .jav a2s. c om*/
            }
        }
    }

    return bytesHeld;
}

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.  jav a 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()));
}

From source file:org.artags.android.app.util.http.HttpUtil.java

/**
 * Post data and attachements//from w  ww  .  j  a va  2  s . c o  m
 * @param url The POST url
 * @param params Parameters
 * @param files Files
 * @return The return value
 * @throws HttpException If an error occurs
 */
public static String post(String url, HashMap<String, String> params, HashMap<String, File> files)
        throws HttpException {
    String ret = "";
    try {
        HttpClient client = new DefaultHttpClient();

        HttpPost post = new HttpPost(url);

        MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

        for (String key : files.keySet()) {
            FileBody bin = new FileBody(files.get(key));
            reqEntity.addPart(key, bin);
        }

        for (String key : params.keySet()) {
            String val = params.get(key);

            reqEntity.addPart(key, new StringBody(val, Charset.forName("UTF-8")));
        }
        post.setEntity(reqEntity);
        HttpResponse response = client.execute(post);

        HttpEntity resEntity = response.getEntity();
        if (resEntity != null) {
            ret = EntityUtils.toString(resEntity);
            Log.i("ARTags:HttpUtil:Post:Response", ret);
        }

        //return response;
    } catch (Exception e) {
        Log.e("ARTags:HttpUtil", "Error : " + e.getMessage());
        throw new HttpException(e.getMessage());
    }
    return ret;
}

From source file:org.droidparts.http.worker.HttpClientWorker.java

private static Map<String, List<String>> getHeaders(HttpResponse resp) {
    HashMap<String, List<String>> headers = new HashMap<String, List<String>>();
    for (Header header : resp.getAllHeaders()) {
        String name = header.getName();
        if (!headers.containsKey(name)) {
            headers.put(name, new ArrayList<String>());
        }/*w  w  w  .  j  a v  a  2 s. c o m*/
        headers.get(name).add(header.getValue());
    }
    return headers;
}

From source file:org.neo4j.nlp.examples.wikipedia.main.java

private static List<Map<String, Object>> getWikipediaArticles() throws IOException {
    final String txUri = "http://localhost:7474/db/data/" + "transaction/commit";
    WebResource resource = Client.create().resource(txUri);

    String query = "MATCH (n:Page) WITH n, rand() as sortOrder " + "ORDER BY sortOrder " + "LIMIT 1000 "
            + "RETURN n.title as title";

    String payload = "{\"statements\" : [ {\"statement\" : \"" + query + "\"} ]}";
    ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON)
            .entity(payload).post(ClientResponse.class);

    ObjectMapper objectMapper = new ObjectMapper();
    HashMap<String, Object> result;
    try {/*from w  ww .j a v  a  2 s  . c o m*/
        result = objectMapper.readValue(response.getEntity(String.class), HashMap.class);
    } catch (Exception e) {
        throw e;
    }
    response.close();

    List<Map<String, Object>> results = new ArrayList<>();

    ArrayList resultSet = ((ArrayList) result.get("results"));
    List<LinkedHashMap<String, Object>> dataSet = (List<LinkedHashMap<String, Object>>) resultSet.stream()
            .map(a -> (LinkedHashMap<String, Object>) a).collect(Collectors.toList());

    List<LinkedHashMap> rows = (List<LinkedHashMap>) ((ArrayList) (dataSet.get(0).get("data"))).stream()
            .map(m -> (LinkedHashMap) m).collect(Collectors.toList());
    ArrayList cols = (ArrayList) (dataSet.get(0).get("columns"));

    for (LinkedHashMap row : rows) {
        ArrayList values = (ArrayList) row.get("row");
        Map<String, Object> resultRecord = new HashMap<>();
        for (int i = 0; i < values.size(); i++) {
            resultRecord.put(cols.get(i).toString(), values.get(i));
        }
        results.add(resultRecord);
    }
    return results;
}

From source file:com.jaredrummler.android.devices.Main.java

private static void createManufacturerJsonFiles(List<String[]> devices) throws IOException {
    File baseDir = new File(OUTPUT_DIR, "manufacturer");
    if (baseDir.exists()) {
        FileUtils.deleteDirectory(baseDir);
    }//  w w  w.  jav a 2 s .  c o m
    baseDir.mkdirs();

    // group all devices with the same codename together
    HashMap<String, List<DeviceInfo>> map = new HashMap<>();
    for (String[] arr : devices) {
        String key = arr[0];
        if (key == null || key.trim().length() == 0) {
            continue;
        }
        List<DeviceInfo> list = map.get(key);
        if (list == null) {
            list = new ArrayList<>();
        }
        list.add(new DeviceInfo(null, arr[1], arr[2], arr[3]));
        map.put(key, list);
    }

    for (Map.Entry<String, List<DeviceInfo>> entry : map.entrySet()) {
        String key = entry.getKey();
        File file = new File(baseDir, key + ".json");
        Manufacturer manufacturer = new Manufacturer(key, entry.getValue());
        FileUtils.write(file, PRETTY_GSON.toJson(manufacturer));
    }
}

From source file:com.ms.app.web.commons.tools.CurrencyFormattor.java

private static NumberFormat getFormat(String key) {
    HashMap<String, NumberFormat> map = formatHolder.get();
    if (map == null) {
        map = new HashMap<String, NumberFormat>(3);
        formatHolder.set(map);// ?
    }/*from   w  ww . j a va2  s  .  c o  m*/
    NumberFormat format = map.get(key);
    if (format == null) {
        format = new DecimalFormat(key);
        map.put(key, format);
        formatHolder.set(map);// ?
    }
    return format;
}