List of usage examples for java.util LinkedHashMap LinkedHashMap
public LinkedHashMap()
From source file:Main.java
public static void main(String[] argv) throws Exception { Map<String, String> map = new LinkedHashMap<String, String>(); map.put("1", "value1"); map.put("2", "value2"); map.put("3", "value3"); map.put("2", "value4"); for (Iterator it = map.keySet().iterator(); it.hasNext();) { Object key = it.next();/*from ww w. j a v a 2 s. c om*/ Object value = map.get(key); } }
From source file:Main.java
public static void main(String[] args) { LinkedHashMap<String, String> lHashMap = new LinkedHashMap<String, String>(); lHashMap.put("1", "One"); lHashMap.put("2", "Two"); lHashMap.put("3", "Three"); Collection c = lHashMap.values(); Iterator itr = c.iterator();//from w w w . j av a 2 s.co m while (itr.hasNext()) { System.out.println(itr.next()); } }
From source file:Main.java
public static void main(String[] args) { Map<String, String> m1 = new LinkedHashMap<String, String>(); m1.put("1", "One"); m1.put("3", "Three"); Map<String, String> m2 = new LinkedHashMap<String, String>(); m2.put("2", "Two"); m2.put("4", "Four"); List<String> list = new ArrayList<String>(); list.addAll(m1.keySet());/* w w w . ja v a 2 s . c o m*/ list.addAll(m2.keySet()); for (String s : list) { System.out.println(s); } }
From source file:Main.java
public static void main(String[] args) { LinkedHashMap<String, String> lHashMap = new LinkedHashMap<String, String>(); lHashMap.put("1", "One"); lHashMap.put("2", "Two"); lHashMap.put("3", "Three"); Set st = lHashMap.keySet();//from ww w . j a v a 2 s . c o m Iterator itr = st.iterator(); while (itr.hasNext()) { System.out.println(itr.next()); } st.remove("2"); boolean blnExists = lHashMap.containsKey("2"); System.out.println(blnExists); }
From source file:Main.java
public static void main(String[] a) { Map<String, String> yourMap = new HashMap<String, String>(); yourMap.put("1", "one"); yourMap.put("2", "two"); yourMap.put("3", "three"); Map<String, Object> map = new LinkedHashMap<String, Object>(); List<String> keyList = new ArrayList<String>(yourMap.keySet()); List<String> valueList = new ArrayList<String>(yourMap.values()); Set<String> sortedSet = new TreeSet<String>(valueList); Object[] sortedArray = sortedSet.toArray(); int size = sortedArray.length; for (int i = 0; i < size; i++) { map.put(keyList.get(valueList.indexOf(sortedArray[i])), sortedArray[i]); }//from www.j a va 2 s.co m Set ref = map.keySet(); Iterator it = ref.iterator(); while (it.hasNext()) { String i = (String) it.next(); System.out.println(i); } }
From source file:CollectionAll.java
public static void main(String[] args) { List list1 = new LinkedList(); list1.add("list"); list1.add("dup"); list1.add("x"); list1.add("dup"); traverse(list1);/*from w w w .j a va 2 s . c o m*/ List list2 = new ArrayList(); list2.add("list"); list2.add("dup"); list2.add("x"); list2.add("dup"); traverse(list2); Set set1 = new HashSet(); set1.add("set"); set1.add("dup"); set1.add("x"); set1.add("dup"); traverse(set1); SortedSet set2 = new TreeSet(); set2.add("set"); set2.add("dup"); set2.add("x"); set2.add("dup"); traverse(set2); LinkedHashSet set3 = new LinkedHashSet(); set3.add("set"); set3.add("dup"); set3.add("x"); set3.add("dup"); traverse(set3); Map m1 = new HashMap(); m1.put("map", "Java2s"); m1.put("dup", "Kava2s"); m1.put("x", "Mava2s"); m1.put("dup", "Lava2s"); traverse(m1.keySet()); traverse(m1.values()); SortedMap m2 = new TreeMap(); m2.put("map", "Java2s"); m2.put("dup", "Kava2s"); m2.put("x", "Mava2s"); m2.put("dup", "Lava2s"); traverse(m2.keySet()); traverse(m2.values()); LinkedHashMap /* from String to String */ m3 = new LinkedHashMap(); m3.put("map", "Java2s"); m3.put("dup", "Kava2s"); m3.put("x", "Mava2s"); m3.put("dup", "Lava2s"); traverse(m3.keySet()); traverse(m3.values()); }
From source file:com.mycompany.mavenpost.HttpTest.java
public static void main(String args[]) throws UnsupportedEncodingException, IOException { System.out.println("this is a test program"); HttpPost httppost = new HttpPost("https://app.monsum.com/api/1.0/api.php"); // Request parameters and other properties. String auth = DEFAULT_USER + ":" + DEFAULT_PASS; byte[] encodedAuth = Base64.encodeBase64(auth.getBytes()); String authHeader = "Basic " + new String(encodedAuth); //String authHeader = "Basic " +"YW5kcmVhcy5zZWZpY2hhQG1hcmtldHBsYWNlLWFuYWx5dGljcy5kZTo5MGRkYjg3NjExMWRiNjNmZDQ1YzUyMjdlNTNmZGIyYlhtMUJQQm03OHhDS1FUVm1OR1oxMHY5TVVyZkhWV3Vh"; httppost.setHeader(HttpHeaders.AUTHORIZATION, authHeader); httppost.setHeader(HttpHeaders.CONTENT_TYPE, "Content-Type: application/json"); Map<String, Object> params = new LinkedHashMap<>(); params.put("SERVICE", "customer.get"); JSONObject json = new JSONObject(); json.put("SERVICE", "customer.get"); //Map<String, Object> params2 = new LinkedHashMap<>(); //params2.put("CUSTOMER_NUMBER","5"); JSONObject array = new JSONObject(); array.put("CUSTOMER_NUMBER", "2"); json.put("FILTER", array); StringEntity param = new StringEntity(json.toString()); httppost.setEntity(param);/* w w w .java 2 s . com*/ HttpClient client = HttpClientBuilder.create().build(); HttpResponse response = client.execute(httppost); int statusCode = response.getStatusLine().getStatusCode(); System.out.println("The status code is " + statusCode); //Execute and get the response. HttpEntity entity = response.getEntity(); Header[] headers = response.getAllHeaders(); for (Header header : headers) { System.out.println("Key : " + header.getName() + " ,Value : " + header.getValue()); } if (entity != null) { String retSrc = EntityUtils.toString(entity); //Discouraged better open a stream and read the data as per Apache manual // parsing JSON //JSONObject result = new JSONObject(retSrc); Gson gson = new GsonBuilder().setPrettyPrinting().create(); JsonParser jp = new JsonParser(); JsonElement je = jp.parse(retSrc); String prettyJsonString = gson.toJson(je); System.out.println(prettyJsonString); } //if (entity != null) { // InputStream instream = entity.getContent(); // try { // final BufferedReader reader = new BufferedReader( // new InputStreamReader(instream)); // String line = null; // while ((line = reader.readLine()) != null) { // System.out.println(line); // } // reader.close(); // } finally { // instream.close(); // } //} }
From source file:org.test.LookupSVNUsers.java
/** * @param args//from w w w . j a va 2 s . c o m * @throws IOException */ public static void main(String[] args) throws IOException { if (args.length != 2) { log.error("USAGE: <svn users file(input)> <git authors file (output)>"); System.exit(-1); } Set<String> unmatchedNameSet = new LinkedHashSet<String>(); Map<String, GitUser> gitUserMap = new LinkedHashMap<String, GitUser>(); String svnAuthorsFile = args[0]; List<String> lines = FileUtils.readLines(new File(svnAuthorsFile)); for (String line : lines) { // intentionally handle both upper and lower case varients of the same name. String svnUserName = line.trim(); if (svnUserName.contains("(")) continue; // skip over this line as we can't use it on the url if (gitUserMap.keySet().contains(svnUserName)) continue; // skip this duplicate. log.info("starting on user = " + svnUserName); String gitName = extractFullName(svnUserName); if (gitName == null) { gitName = extractFullName(svnUserName.toLowerCase()); } if (gitName == null) { unmatchedNameSet.add(svnUserName); } else { gitUserMap.put(svnUserName, new GitUser(svnUserName, gitName)); log.info("mapped user (" + svnUserName + ") to: " + gitName); } } List<String> mergedList = new ArrayList<String>(); mergedList.add("# GENERATED "); List<String> userNameList = new ArrayList<String>(); userNameList.addAll(gitUserMap.keySet()); Collections.sort(userNameList); for (String userName : userNameList) { GitUser gUser = gitUserMap.get(userName); mergedList.add(gUser.getSvnAuthor() + " = " + gUser.getGitUser() + " <" + gUser.getSvnAuthor() + "@users.sourceforge.net>"); } for (String username : unmatchedNameSet) { log.warn("failed to match SVN User = " + username); // add in the unmatched entries as is. mergedList.add(username + " = " + username + " <" + username + "@users.sourceforge.net>"); } FileUtils.writeLines(new File(args[1]), "UTF-8", mergedList); }
From source file:org.jaqpot.core.model.Report.java
public static void main(String[] args) throws JsonProcessingException { Report report = new Report(); LinkedHashMap<String, Object> single = new LinkedHashMap<>(); single.put("calculation1", 325.15); single.put("calculation2", "A"); single.put("calculation3", "whatever"); single.put("calculation4", 15); LinkedHashMap<String, ArrayCalculation> arrays = new LinkedHashMap<>(); ArrayCalculation a1 = new ArrayCalculation(); a1.setColNames(Arrays.asList("column A", "column B", "column C")); LinkedHashMap<String, List<Object>> v1 = new LinkedHashMap<>(); v1.put("row1", Arrays.asList(5.0, 1, 30)); v1.put("row2", Arrays.asList(6.0, 12, 34)); v1.put("row3", Arrays.asList(7.0, 11, 301)); a1.setValues(v1);//from ww w . j ava2 s. c o m ArrayCalculation a2 = new ArrayCalculation(); a2.setColNames(Arrays.asList("column 1", "column 2", "column 3")); LinkedHashMap<String, List<Object>> v2 = new LinkedHashMap<>(); v2.put("row1", Arrays.asList(5.0, 1, 30)); v2.put("row2", Arrays.asList(6.0, 12, 34)); v2.put("row3", Arrays.asList(7.0, 11, 301)); a2.setValues(v2); arrays.put("calculation 5", a1); arrays.put("calcluation 6", a2); LinkedHashMap<String, String> figures = new LinkedHashMap<>(); figures.put("figure1", "fa9ifj2ifjaspldkfjapwodfjaspoifjaspdofijaf283jfo2iefj"); figures.put("figure2", "1okwejf-o2eifj-2fij2e-fijeflksdjfksdjfpskdfjspdokfjsdpf"); report.setSingleCalculations(single); report.setArrayCalculations(arrays); report.setFigures(figures); ObjectMapper mapper = new ObjectMapper(); String reportString = mapper.writeValueAsString(report); System.out.println(reportString); }
From source file:DifferentalEvolution.java
public static void main(String[] args) { solutions = new ArrayList<Double>(ControlVariables.RUNS_PER_FUNCTION); /* An array of the benchmark functions to evalute */ benchmarkFunctions = new ArrayList<FitnessFunction>(); benchmarkFunctions.add(new DeJong()); benchmarkFunctions.add(new HyperEllipsoid()); benchmarkFunctions.add(new Schwefel()); benchmarkFunctions.add(new RosenbrocksValley()); benchmarkFunctions.add(new Rastrigin()); /* Apply the differential evolution algorithm to each benchmark function */ for (FitnessFunction benchmarkFunction : benchmarkFunctions) { /* Set the fitness function for the current benchmark function */ fitnessFunction = benchmarkFunction; /* Execute the differential evolution algorithm a number of times per function */ for (int runs = 0; runs < ControlVariables.RUNS_PER_FUNCTION; ++runs) { int a; int b; int c; boolean validVector = false; Vector noisyVector = null; /* Reset the array of the best values found */ prevAmount = 0;//from w w w .ja va2 s. c o m lowestFit = new LinkedHashMap<Integer, Double>(); lowestFit.put(prevAmount, Double.MAX_VALUE); initPopulation(fitnessFunction.getBounds()); /* Reset the fitness function NFC each time */ fitnessFunction.resetNFC(); while (fitnessFunction.getNFC() < ControlVariables.MAX_FUNCTION_CALLS) { for (int i = 0; i < ControlVariables.POPULATION_SIZE; i++) { // Select 3 Mutually Exclusive Parents i != a != b != c while (!validVector) { do { a = getRandomIndex(); } while (a == i); do { b = getRandomIndex(); } while (b == i || b == a); do { c = getRandomIndex(); } while (c == i || c == a || c == b); // Catch invalid vectors try { validVector = true; noisyVector = VectorOperations.mutation(population.get(c), population.get(b), population.get(a)); } catch (IllegalArgumentException e) { validVector = false; } } validVector = false; Vector trialVector = VectorOperations.crossover(population.get(i), noisyVector, random); trialVector.setFitness(fitnessFunction.evaluate(trialVector)); population.set(i, VectorOperations.selection(population.get(i), trialVector)); /* Get the best fitness value found so far */ if (population.get(i).getFitness() < lowestFit.get(prevAmount)) { prevAmount = fitnessFunction.getNFC(); bestValue = population.get(i).getFitness(); lowestFit.put(prevAmount, bestValue); } } } /* save the best value found for the entire DE algorithm run */ solutions.add(bestValue); } /* Display the mean and standard deviation */ System.out.println("\nResults for " + fitnessFunction.getName()); DescriptiveStatistics stats = new DescriptiveStatistics(Doubles.toArray(solutions)); System.out.println("AVERAGE BEST FITNESS: " + stats.getMean()); System.out.println("STANDARD DEVIATION: " + stats.getStandardDeviation()); /* Set the last value (NFC) to the best value found */ lowestFit.put(ControlVariables.MAX_FUNCTION_CALLS, bestValue); /* Plot the best value found vs. NFC */ PerformanceGraph.plot(lowestFit, fitnessFunction.getName()); /* Reset the results for the next benchmark function to be evaluated */ solutions.clear(); lowestFit.clear(); bestValue = Double.MAX_VALUE; } }