Example usage for java.util TreeMap put

List of usage examples for java.util TreeMap put

Introduction

In this page you can find the example usage for java.util TreeMap 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 void main(String[] args) {

    TreeMap<Integer, String> treemap = new TreeMap<Integer, String>();
    TreeMap<Integer, String> treemapclone = new TreeMap<Integer, String>();

    // populating tree map
    treemap.put(2, "two");
    treemap.put(1, "one");
    treemap.put(3, "three");
    treemap.put(6, "six");
    treemap.put(5, "from java2s.com");

    // cloning tree map
    System.out.println("Cloning tree map");
    treemapclone = (TreeMap) treemap.clone();

    System.out.println("Original map: " + treemap);
    System.out.println("Cloned map: " + treemapclone);
}

From source file:Main.java

public static void main(String[] args) {

    TreeMap<Integer, String> treemap = new TreeMap<Integer, String>();
    TreeMap<Integer, String> treemapheadincl = new TreeMap<Integer, String>();

    // populating tree map
    treemap.put(2, "two");
    treemap.put(1, "one");
    treemap.put(3, "three");
    treemap.put(6, "six");
    treemap.put(5, "from java2s.com");

    // getting head map inclusive 3
    treemapheadincl = treemap.headMap(3, true);

    System.out.println("Checking values of the map");
    System.out.println("Value is: " + treemapheadincl);
}

From source file:Main.java

public static void main(String[] args) {

    TreeMap<Integer, String> treemap = new TreeMap<Integer, String>();
    TreeMap<Integer, String> treemap_putall = new TreeMap<Integer, String>();

    // populating tree map
    treemap.put(2, "two");
    treemap.put(1, "one");
    treemap.put(3, "three");
    treemap.put(6, "six");
    treemap.put(5, "from java2s.com");

    treemap_putall.put(1, "1");
    treemap_putall.put(2, "2");
    treemap_putall.put(7, "7");

    System.out.println("Value before modification: " + treemap);

    // Putting 2nd map in 1st map
    treemap.putAll(treemap_putall);/* w w  w. ja  v a 2 s. c o  m*/

    System.out.println("Value after modification: " + treemap);
}

From source file:edu.csun.ecs.cs.multitouchj.application.chopsticks.Chopsticks.java

public static void main(String[] args) {
    LinkedList<String> arguments = new LinkedList<String>();
    for (String argument : args) {
        arguments.add(argument);// w  w w.  jav a 2s .c  o  m
    }

    TreeMap<String, String> parameters = new TreeMap<String, String>();
    if (arguments.contains("-ix")) {
        parameters.put(ObjectObserverMoteJ.Parameter.InverseX.toString(), "");
    }
    if (arguments.contains("-iy")) {
        parameters.put(ObjectObserverMoteJ.Parameter.InverseY.toString(), "");
    }

    Chopsticks chopsticks = new Chopsticks();
    chopsticks.run(parameters);
}

From source file:edu.csun.ecs.cs.multitouchj.ui.test.PhotoTest.java

public static void main(String[] args) {
    LinkedList<String> arguments = new LinkedList<String>();
    for (String argument : args) {
        arguments.add(argument);/*from  w  ww. j  a  v a2s .co m*/
    }

    TreeMap<String, String> parameters = new TreeMap<String, String>();
    if (arguments.contains("-ix")) {
        parameters.put(ObjectObserverMoteJ.Parameter.InverseX.toString(), "");
    }
    if (arguments.contains("-iy")) {
        parameters.put(ObjectObserverMoteJ.Parameter.InverseY.toString(), "");
    }

    PhotoTest photoTest = new PhotoTest();
    photoTest.run(parameters);
}

From source file:edu.csun.ecs.cs.multitouchj.application.whiteboard.Whiteboard.java

public static void main(String[] args) {
    LinkedList<String> arguments = new LinkedList<String>();
    for (String argument : args) {
        arguments.add(argument);/*from   ww w  .  ja  va 2s .co  m*/
    }

    TreeMap<String, String> parameters = new TreeMap<String, String>();
    if (arguments.contains("-ix")) {
        parameters.put(ObjectObserverMoteJ.Parameter.InverseX.toString(), "");
    }
    if (arguments.contains("-iy")) {
        parameters.put(ObjectObserverMoteJ.Parameter.InverseY.toString(), "");
    }

    Whiteboard whiteboard = new Whiteboard();
    whiteboard.run(parameters);
}

From source file:gsn.storage.SQLUtils.java

public static void main(String[] args) {
    TreeMap<CharSequence, CharSequence> map = new TreeMap<CharSequence, CharSequence>(
            new CaseInsensitiveComparator());
    String query = "seLect ali.fd, x.x, fdfd.fdfd, *.r, * from x,x, bla, x whEre k";
    map.put("x", "done");
    CharSequence out = newRewrite(query, map);
    System.out.println(out.toString());
    System.out.println(extractProjection(query));
    out = newRewrite(extractProjection(query), map);
    System.out.println(out.toString());
}

From source file:com.github.xbn.examples.io.non_xbn.SizeOrderAllFilesInDirXmpl.java

public static final void main(String[] ignored) {
    File fDir = (new File("R:\\jeffy\\programming\\sandbox\\xbnjava\\xbn\\"));
    Collection<File> cllf = FileUtils.listFiles(fDir, (new String[] { "java" }), true);

    //Add all file paths to a Map, keyed by size.
    //It's actually a map of lists-of-files, to
    //allow multiple files that happen to have the
    //same length.

    TreeMap<Long, List<File>> tmFilesBySize = new TreeMap<Long, List<File>>();
    Iterator<File> itrf = cllf.iterator();
    while (itrf.hasNext()) {
        File f = itrf.next();//from ww  w  . ja  va2s  .  com
        Long LLen = f.length();
        if (!tmFilesBySize.containsKey(LLen)) {
            ArrayList<File> alf = new ArrayList<File>();
            alf.add(f);
            tmFilesBySize.put(LLen, alf);
        } else {
            tmFilesBySize.get(LLen).add(f);
        }
    }

    //Iterate backwards by key through the map. For each
    //List<File>, iterate through the files, printing out
    //its size and path.

    ArrayList<Long> alSize = new ArrayList<Long>(tmFilesBySize.keySet());
    for (int i = alSize.size() - 1; i >= 0; i--) {
        itrf = tmFilesBySize.get(alSize.get(i)).iterator();
        while (itrf.hasNext()) {
            File f = itrf.next();
            System.out.println(f.length() + ": " + f.getPath());
        }
    }
}

From source file:com.inkubator.common.util.NewMain.java

/**
 * @param args the command line arguments
 *///ww w  .j a va2s .c o  m
public static void main(String[] args) throws IOException {

    File file1 = new File(
            "C:\\Users\\deni.fahri\\AppData\\Roaming\\Skype\\My Skype Received Files\\JSON_Ek\\Surabaya\\Page1.txt");
    File file2 = new File(
            "C:\\Users\\deni.fahri\\AppData\\Roaming\\Skype\\My Skype Received Files\\JSON_Ek\\Surabaya\\Page2.txt");
    //        File file3 = new File("C:\\Users\\deni.fahri\\AppData\\Roaming\\Skype\\My Skype Received Files\\json\\json\\menado\\page3.txt");
    File file3 = new File(
            "C:\\Users\\deni.fahri\\AppData\\Roaming\\Skype\\My Skype Received Files\\JSON_Ek\\Surabaya\\Page3.txt");
    File file4 = new File(
            "C:\\Users\\deni.fahri\\AppData\\Roaming\\Skype\\My Skype Received Files\\JSON_Ek\\Surabaya\\Page4.txt");
    File file5 = new File(
            "C:\\Users\\deni.fahri\\AppData\\Roaming\\Skype\\My Skype Received Files\\JSON_Ek\\Surabaya\\Page5.txt");
    File file6 = new File(
            "C:\\Users\\deni.fahri\\AppData\\Roaming\\Skype\\My Skype Received Files\\JSON_Ek\\Surabaya\\Page6.txt");
    //        File file7 = new File("C:\\Users\\deni.fahri\\AppData\\Roaming\\Skype\\My Skype Received Files\\Bandung\\Bandung\\Page 7.txt");
    //        File file8 = new File("C:\\Users\\deni.fahri\\AppData\\Roaming\\Skype\\My Skype Received Files\\Bandung\\Bandung\\Page 8.txt");
    //        File file9 = new File("C:\\Users\\deni.fahri\\AppData\\Roaming\\Skype\\My Skype Received Files\\Bandung\\Bandung\\Page 9.txt");
    //        File file10 = new File("C:\\Users\\deni.fahri\\AppData\\Roaming\\Skype\\My Skype Received Files\\Bandung\\Bandung\\Page 10.txt");
    //        File file11 = new File("C:\\Users\\deni.fahri\\AppData\\Roaming\\Skype\\My Skype Received Files\\Bandung\\Bandung\\Page 11.txt");
    //        File file12 = new File("C:\\Users\\deni.fahri\\AppData\\Roaming\\Skype\\My Skype Received Files\\Bandung\\Bandung\\Page 12.txt");
    //        File file13 = new File("C:\\Users\\deni.fahri\\AppData\\Roaming\\Skype\\My Skype Received Files\\Bandung\\Bandung\\Page 13.txt");
    //        File file14 = new File("C:\\Users\\deni.fahri\\AppData\\Roaming\\Skype\\My Skype Received Files\\Bandung\\Bandung\\Page 14.txt");
    //        File file15 = new File("C:\\Users\\deni.fahri\\AppData\\Roaming\\Skype\\My Skype Received Files\\Bandung\\Bandung\\Page 15.txt");
    //        File file16 = new File("C:\\Users\\deni.fahri\\Downloads\\page16.txt");

    //        File file2 = new File("C:\\Users\\deni.fahri\\Documents\\hasil.txt");
    String agoda = FilesUtil.getAsStringFromFile(file1);
    String agoda1 = FilesUtil.getAsStringFromFile(file2);
    String agoda2 = FilesUtil.getAsStringFromFile(file3);
    String agoda3 = FilesUtil.getAsStringFromFile(file4);
    String agoda4 = FilesUtil.getAsStringFromFile(file5);
    String agoda5 = FilesUtil.getAsStringFromFile(file6);
    //        String agoda6 = FilesUtil.getAsStringFromFile(file7);
    //        String agoda7 = FilesUtil.getAsStringFromFile(file8);
    //        String agoda8 = FilesUtil.getAsStringFromFile(file9);
    //        String agoda9 = FilesUtil.getAsStringFromFile(file10);
    //        String agoda10 = FilesUtil.getAsStringFromFile(file11);
    //        String agoda11 = FilesUtil.getAsStringFromFile(file12);
    //        String agoda12 = FilesUtil.getAsStringFromFile(file13);
    //        String agoda13 = FilesUtil.getAsStringFromFile(file14);
    //        String agoda14 = FilesUtil.getAsStringFromFile(file15);
    //        String agoda15 = FilesUtil.getAsStringFromFile(file16);
    ////        System.out.println(" Test Nya adalah :" + agoda);
    ////        String a=StringUtils.substringAfter("\"HotelTranslatedName\":", agoda);
    ////        System.out.println(" hasil; "+a);
    ////        // TODO code application logic here
    ////        System.out.println("Nilai " + JsonConverter.getValueByKeyStatic(agoda, "HotelTranslatedName"));
    TypeToken<List<HotelModel>> token = new TypeToken<List<HotelModel>>() {
    };
    Gson gson = new GsonBuilder().create();
    //        List<HotelModel> data = new ArrayList<>();
    //        HotelModel hotelModel = new HotelModel();
    //        hotelModel.setAddress("sdfsdffsfsdfsdfdsfdsf");
    //        hotelModel.setAccommodationName("Aku");
    //        HotelModel hotelModel1 = new HotelModel();
    //        hotelModel1.setAddress("sdfsdffsfsdfsdfdsfdsf");
    //        hotelModel1.setAccommodationName("Avvvku");
    //        HotelModel hotelModel2 = new HotelModel();
    //        hotelModel2.setAddress("sdfsdffsfsdfsdfdsfdsf");
    //        hotelModel2.setAccommodationName("Akvvvu");
    //        data.add(hotelModel);
    //        data.add(hotelModel1);
    //        data.add(hotelModel2);
    //        String json = gson.toJson(data);
    List<HotelModel> total = new ArrayList<>();
    List<HotelModel> data1 = new ArrayList<>();
    List<HotelModel> data2 = new ArrayList<>();
    List<HotelModel> data3 = new ArrayList<>();
    List<HotelModel> data4 = new ArrayList<>();
    List<HotelModel> data5 = new ArrayList<>();
    List<HotelModel> data6 = new ArrayList<>();
    List<HotelModel> data7 = new ArrayList<>();
    List<HotelModel> data8 = new ArrayList<>();
    List<HotelModel> data9 = new ArrayList<>();
    List<HotelModel> data10 = new ArrayList<>();
    List<HotelModel> data11 = new ArrayList<>();
    List<HotelModel> data12 = new ArrayList<>();
    List<HotelModel> data13 = new ArrayList<>();
    List<HotelModel> data14 = new ArrayList<>();
    List<HotelModel> data15 = new ArrayList<>();
    List<HotelModel> data16 = new ArrayList<>();

    data1 = gson.fromJson(agoda, token.getType());
    data2 = gson.fromJson(agoda1, token.getType());
    data3 = gson.fromJson(agoda2, token.getType());
    data4 = gson.fromJson(agoda3, token.getType());
    data5 = gson.fromJson(agoda4, token.getType());
    data6 = gson.fromJson(agoda5, token.getType());
    //        data7 = gson.fromJson(agoda6, token.getType());
    //        data8 = gson.fromJson(agoda7, token.getType());
    //        data9 = gson.fromJson(agoda8, token.getType());
    //        data10 = gson.fromJson(agoda9, token.getType());
    //        data11 = gson.fromJson(agoda10, token.getType());
    //        data12 = gson.fromJson(agoda11, token.getType());
    //        data13 = gson.fromJson(agoda12, token.getType());
    //        data14 = gson.fromJson(agoda13, token.getType());
    //        data15 = gson.fromJson(agoda14, token.getType());
    //        data16 = gson.fromJson(agoda15, token.getType());
    total.addAll(data1);
    total.addAll(data2);
    total.addAll(data3);
    total.addAll(data4);
    total.addAll(data5);
    total.addAll(data6);
    //        total.addAll(data7);
    //        total.addAll(data8);
    //        total.addAll(data9);
    //        total.addAll(data10);
    //        total.addAll(data11);
    //        total.addAll(data12);
    //        total.addAll(data13);
    //        total.addAll(data14);
    //        total.addAll(data15);
    //        total.addAll(data16);
    System.out.println(" Ukurannn nya " + total.size());

    //        System.out.println(" Ukurannya " + data2.size());
    for (HotelModel mode : total) {
        System.out.println(mode);
    }
    //        HotelModel hotelModel = gson.fromJson(agoda, HotelModel.class);
    //        String Data = hotelModel.getHotelTranslatedName() + ";" + hotelModel.getStarRating() + ";" + hotelModel.getAddress() + ";" + hotelModel.getIsFreeWifi();
    //        FilesUtil.writeToFileFromString(file2, Data);
    //        System.out.println(hotelModel);
    //
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("Agoda Data Hotel Surabaya");

    ////
    TreeMap<String, Object[]> datatoExel = new TreeMap<>();
    int i = 1;
    //        datatoExel.put("1", new Object[]{"Hotel Agoda Jakarta"});
    datatoExel.put("1", new Object[] { "Nama Hotel", "Arena", "Alamat", "Rating", "Apakah Gratis Wifi",
            "Harga Mulai Dari", "Longitude", "Latitude" });
    for (HotelModel mode : total) {
        datatoExel.put(String.valueOf(i + 1),
                new Object[] { mode.getHotelTranslatedName(), mode.getAreaName(), mode.getAddress(),
                        mode.getStarRating(), mode.getIsFreeWifi(),
                        mode.getTextPrice() + " " + mode.getCurrencyCode(), mode.getCoordinate().getLongitude(),
                        mode.getCoordinate().getLatitude() });
        i++;
    }
    //
    ////          int i=1;
    ////        for (HotelModel mode : data2) {
    ////             datatoExel.put(String.valueOf(i), new Object[]{1d, "John", 1500000d});
    //////        }
    ////       
    ////        datatoExel.put("4", new Object[]{3d, "Dean", 700000d});
    ////
    Set<String> keyset = datatoExel.keySet();
    int rownum = 0;
    for (String key : keyset) {
        Row row = sheet.createRow(rownum++);
        Object[] objArr = datatoExel.get(key);
        int cellnum = 0;
        for (Object obj : objArr) {
            Cell cell = row.createCell(cellnum++);
            if (obj instanceof Date) {
                cell.setCellValue((Date) obj);
            } else if (obj instanceof Boolean) {
                cell.setCellValue((Boolean) obj);
            } else if (obj instanceof String) {
                cell.setCellValue((String) obj);
            } else if (obj instanceof Double) {
                cell.setCellValue((Double) obj);
            }
        }
    }

    try {
        FileOutputStream out = new FileOutputStream(new File("C:\\Users\\deni.fahri\\Documents\\Surabaya.xls"));
        workbook.write(out);
        out.close();
        System.out.println("Excel written successfully..");

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.cloud.test.utils.SubmitCert.java

public static void main(String[] args) {
    // Parameters
    List<String> argsList = Arrays.asList(args);
    Iterator<String> iter = argsList.iterator();
    while (iter.hasNext()) {
        String arg = iter.next();

        if (arg.equals("-c")) {
            certFileName = iter.next();// w  w  w  .j  a v  a 2  s.  c o  m
        }

        if (arg.equals("-s")) {
            secretKey = iter.next();
        }

        if (arg.equals("-a")) {
            apiKey = iter.next();
        }

        if (arg.equals("-action")) {
            url = "Action=" + iter.next();
        }
    }

    Properties prop = new Properties();
    try {
        prop.load(new FileInputStream("conf/tool.properties"));
    } catch (IOException ex) {
        s_logger.error("Error reading from conf/tool.properties", ex);
        System.exit(2);
    }

    host = prop.getProperty("host");
    port = prop.getProperty("port");

    if (url.equals("Action=SetCertificate") && certFileName == null) {
        s_logger.error("Please set path to certificate (including file name) with -c option");
        System.exit(1);
    }

    if (secretKey == null) {
        s_logger.error("Please set secretkey  with -s option");
        System.exit(1);
    }

    if (apiKey == null) {
        s_logger.error("Please set apikey with -a option");
        System.exit(1);
    }

    if (host == null) {
        s_logger.error("Please set host in tool.properties file");
        System.exit(1);
    }

    if (port == null) {
        s_logger.error("Please set port in tool.properties file");
        System.exit(1);
    }

    TreeMap<String, String> param = new TreeMap<String, String>();

    String req = "GET\n" + host + ":" + prop.getProperty("port") + "\n/" + prop.getProperty("accesspoint")
            + "\n";
    String temp = "";

    if (certFileName != null) {
        cert = readCert(certFileName);
        param.put("cert", cert);
    }

    param.put("AWSAccessKeyId", apiKey);
    param.put("Expires", prop.getProperty("expires"));
    param.put("SignatureMethod", prop.getProperty("signaturemethod"));
    param.put("SignatureVersion", "2");
    param.put("Version", prop.getProperty("version"));

    StringTokenizer str1 = new StringTokenizer(url, "&");
    while (str1.hasMoreTokens()) {
        String newEl = str1.nextToken();
        StringTokenizer str2 = new StringTokenizer(newEl, "=");
        String name = str2.nextToken();
        String value = str2.nextToken();
        param.put(name, value);
    }

    //sort url hash map by key
    Set c = param.entrySet();
    Iterator it = c.iterator();
    while (it.hasNext()) {
        Map.Entry me = (Map.Entry) it.next();
        String key = (String) me.getKey();
        String value = (String) me.getValue();
        try {
            temp = temp + key + "=" + URLEncoder.encode(value, "UTF-8") + "&";
        } catch (Exception ex) {
            s_logger.error("Unable to set parameter " + value + " for the command " + param.get("command"), ex);
        }

    }
    temp = temp.substring(0, temp.length() - 1);
    String requestToSign = req + temp;
    String signature = UtilsForTest.signRequest(requestToSign, secretKey);
    String encodedSignature = "";
    try {
        encodedSignature = URLEncoder.encode(signature, "UTF-8");
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    String url = "http://" + host + ":" + prop.getProperty("port") + "/" + prop.getProperty("accesspoint") + "?"
            + temp + "&Signature=" + encodedSignature;
    s_logger.info("Sending request with url:  " + url + "\n");
    sendRequest(url);
}