Example usage for java.util HashMap HashMap

List of usage examples for java.util HashMap HashMap

Introduction

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

Prototype

public HashMap() 

Source Link

Document

Constructs an empty HashMap with the default initial capacity (16) and the default load factor (0.75).

Usage

From source file:contractEditor.contractClients.java

public static void main(String[] args) {

    JSONObject obj = new JSONObject();
    obj.put("name", "clientTemplate");
    obj.put("context", "VM-deployment");
    //obj.put("Context", new Integer);

    HashMap serviceRequirement = new HashMap();

    HashMap serviceDescription = new HashMap();
    serviceRequirement.put("VM1_volume", "18_GB");
    serviceDescription.put("VM1_purpose", "dev");
    serviceDescription.put("VM1_data", "private");
    serviceDescription.put("VM1_application", "internal");

    serviceRequirement.put("VM2_volume", "20_GB");
    serviceDescription.put("VM2_purpose", "prod");
    serviceDescription.put("VM2_data", "public");
    serviceDescription.put("VM2_application", "business");

    serviceRequirement.put("VM3_volume", "30_GB");
    serviceDescription.put("VM3_purpose", "test");
    serviceDescription.put("VM3_data", "public");
    serviceDescription.put("VM3_application", "business");

    serviceRequirement.put("VM4_volume", "20_GB");
    serviceDescription.put("VM4_purpose", "prod");
    serviceDescription.put("VM4_data", "public");
    serviceDescription.put("VM4_application", "business");

    obj.put("serviceRequirement", serviceRequirement);
    obj.put("serviceDescription", serviceDescription);

    HashMap gauranteeTerm = new HashMap();
    gauranteeTerm.put("VM1_availability", "more_97_percentage");
    gauranteeTerm.put("VM2_availability", "more_99_percentage");
    gauranteeTerm.put("VM3_availability", "more_95_percentage");
    gauranteeTerm.put("VM4_availability", "more_99_percentage");
    obj.put("gauranteeTerm", gauranteeTerm);

    //Constraint1

    HashMap host_rule1 = new HashMap();
    HashMap VM_rule1 = new HashMap();
    host_rule1.put("certificate", "true");
    VM_rule1.put("purpose", "dev");

    ArrayList rule1 = new ArrayList();
    rule1.add("permission");
    rule1.add(host_rule1);//  w w w  .  j  a v a2s.com
    rule1.add(VM_rule1);

    HashMap host_rule1_2 = new HashMap();
    HashMap VM_rule1_2 = new HashMap();
    host_rule1_2.put("certificate", "true");
    VM_rule1_2.put("purpose", "prod");

    ArrayList rule1_2 = new ArrayList();
    rule1_2.add("permission");
    rule1_2.add(host_rule1_2);
    rule1_2.add(VM_rule1_2);

    HashMap host_rule1_3 = new HashMap();
    HashMap VM_rule1_3 = new HashMap();
    host_rule1_3.put("certificate", "true");
    VM_rule1_3.put("purpose", "test");

    ArrayList rule1_3 = new ArrayList();
    rule1_3.add("permission");
    rule1_3.add(host_rule1_3);
    rule1_3.add(VM_rule1_3);

    HashMap host_rule2 = new HashMap();
    HashMap VM_rule2 = new HashMap();
    host_rule2.put("location", "France");
    VM_rule2.put("ID", "VM2");

    ArrayList rule2 = new ArrayList();
    rule2.add("permission");
    rule2.add(host_rule2);
    rule2.add(VM_rule2);

    HashMap host_rule2_1 = new HashMap();
    HashMap VM_rule2_1 = new HashMap();
    host_rule2_1.put("location", "UK");
    VM_rule2_1.put("ID", "VM2");

    ArrayList rule2_1 = new ArrayList();
    rule2_1.add("permission");
    rule2_1.add(host_rule2_1);
    rule2_1.add(VM_rule2_1);

    HashMap host_rule3 = new HashMap();
    HashMap VM_rule3 = new HashMap();
    host_rule3.put("location", "France");
    VM_rule3.put("application", "business");

    ArrayList rule3 = new ArrayList();
    rule3.add("permission");
    rule3.add(host_rule3);
    rule3.add(VM_rule3);

    HashMap host_rule3_1 = new HashMap();
    HashMap VM_rule3_1 = new HashMap();
    host_rule3_1.put("location", "UK");
    VM_rule3_1.put("application", "business");

    ArrayList rule3_1 = new ArrayList();
    rule3_1.add("permission");
    rule3_1.add(host_rule3_1);
    rule3_1.add(VM_rule3_1);

    HashMap VMSeperation_rule_1_1 = new HashMap();
    HashMap VMSeperation_rule_1_2 = new HashMap();

    VMSeperation_rule_1_1.put("ID", "VM1");
    VMSeperation_rule_1_2.put("ID", "VM3");

    ArrayList rule4 = new ArrayList();
    rule4.add("separation");
    rule4.add(VMSeperation_rule_1_1);
    rule4.add(VMSeperation_rule_1_2);

    ArrayList policyInConstraint1 = new ArrayList();
    policyInConstraint1.add(rule1);
    policyInConstraint1.add(rule1_2);
    policyInConstraint1.add(rule1_3);

    policyInConstraint1.add(rule2);
    policyInConstraint1.add(rule2_1);

    policyInConstraint1.add(rule3);
    policyInConstraint1.add(rule3_1);

    policyInConstraint1.add(rule4);

    ArrayList creationConstraint1 = new ArrayList();
    creationConstraint1.add("RP4");
    creationConstraint1.add("true");
    creationConstraint1.add("true");
    creationConstraint1.add(policyInConstraint1);

    ArrayList totalConstraint = new ArrayList();
    totalConstraint.add(creationConstraint1);

    obj.put("creationConstraint", totalConstraint);

    try {

        FileWriter file = new FileWriter("confClient" + File.separator + "test3.json");
        file.write(obj.toJSONString());
        file.flush();
        file.close();

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

    System.out.print(obj);

    /*
            
    JSONParser parser = new JSONParser();
            
    try {
            
    Object obj2 = parser.parse(new FileReader("test2.json"));
            
    JSONObject jsonObject = (JSONObject) obj2;
            
        HashMap serviceDescription2=(HashMap) jsonObject.get("serviceDescription");
                 
        method.printHashMap(serviceDescription2);
                
                
        HashMap gauranteeTerm2=(HashMap) jsonObject.get("gauranteeTerm");
                 
        method.printHashMap(gauranteeTerm2);
                
                
                
        ArrayList creationConstraint=(ArrayList) jsonObject.get("creationConstraint");
                
        method.printArrayList(creationConstraint);
            
            
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    } catch (ParseException e) {
    e.printStackTrace();
    }
            
            
            
            
            
    */

}

From source file:com.apress.prospringintegration.wiretap.WireTapExample.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:wiretap/wiretap.xml");

    MessageChannel input = context.getBean("input", MessageChannel.class);
    PollableChannel output = context.getBean("output", PollableChannel.class);

    Map<String, String> customerMap = new HashMap<String, String>();
    customerMap.put("firstName", "John");
    customerMap.put("lastName", "Smith");
    customerMap.put("address", "100 State Street");
    customerMap.put("city", "Los Angeles");
    customerMap.put("state", "CA");
    customerMap.put("zip", "90064");

    Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build();
    input.send(message);/*from   w  ww. j av  a2  s.  c om*/

    Message<?> reply = output.receive();
    System.out.println("received: " + reply.getPayload());
}

From source file:com.apress.prospringintegration.transform.HeaderEnricher.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:header-enricher.xml");

    MessageChannel input = context.getBean("input", MessageChannel.class);
    PollableChannel output = context.getBean("output", PollableChannel.class);

    Map<String, String> customerMap = new HashMap<String, String>();
    customerMap.put("firstName", "John");
    customerMap.put("lastName", "Smith");
    customerMap.put("address", "100 State Street");
    customerMap.put("city", "Los Angeles");
    customerMap.put("state", "CA");
    customerMap.put("zip", "90064");

    Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build();
    input.send(message);/*w w  w. j  ava 2 s.c  o m*/

    Message<?> reply = output.receive();
    System.out.println("received: " + reply);
}

From source file:Main.java

public static void main(String[] args) {

    File workingDirectory = new File("C:" + File.separator + "Invoices");

    File template = new File(workingDirectory.getAbsolutePath() + File.separator + "invoiceTemplate.tex");

    File tempDir = new File(workingDirectory.getAbsolutePath() + File.separator + "temp");
    if (!tempDir.isDirectory()) {
        tempDir.mkdir();/*from  ww  w.jav  a 2s. c o m*/
    }

    File invoice1 = new File(tempDir.getAbsolutePath() + File.separator + "invoice1.tex");
    File invoice2 = new File(tempDir.getAbsolutePath() + File.separator + "invoice2.tex");

    try {

        HashMap<String, String> data = new HashMap<String, String>();

        data.put("Number", "1");
        data.put("Customer name", "Ivan Pfeiffer");
        data.put("Customer street", "Schwarzer Weg 4");
        data.put("Customer zip", "13505 Berlin");
        data.put("Development", "Software");
        data.put("Price", "500");

        JLRConverter converter = new JLRConverter("::", ":::");
        if (!converter.parse(template, invoice1, data)) {
            System.out.println(converter.getErrorMessage());
        }

        data.put("Number", "2");
        data.put("Customer name", "Mike Mueller");
        data.put("Customer street", "Prenzlauer Berg 12");
        data.put("Customer zip", "10405 Berlin");
        data.put("Development", "Hardware");
        data.put("Price", "2350");

        if (!converter.parse(template, invoice2, data)) {
            System.out.println(converter.getErrorMessage());
        }

        File desktop = new File(System.getProperty("user.home") + File.separator + "Desktop");

        JLRGenerator pdfGen = new JLRGenerator();

        pdfGen.deleteTempTexFile(false);

        if (!pdfGen.generate(invoice1, desktop, workingDirectory)) {
            System.out.println(pdfGen.getErrorMessage());
        }

        JLROpener.open(pdfGen.getPDF());

        if (!pdfGen.generate(invoice2, desktop, workingDirectory)) {
            System.out.println(pdfGen.getErrorMessage());
        }

        JLROpener.open(pdfGen.getPDF());

    } catch (IOException ex) {
        System.err.println(ex.getMessage());
    }
}

From source file:com.rest.samples.getReportFromJasperServerWithSeparateAuthFormatURL.java

public static void main(String[] args) {
    // TODO code application logic here
    Map<String, String> params = new HashMap<String, String>();
    params.put("host", "10.49.28.3");
    params.put("port", "8081");
    params.put("reportName", "vencimientos");
    params.put("parametros", "feini=2016-09-30&fefin=2016-09-30");
    StrSubstitutor sub = new StrSubstitutor(params, "{", "}");
    String urlTemplate = "http://{host}:{port}/jasperserver/rest_v2/reports/Reportes/{reportName}.pdf?{parametros}";
    String url = sub.replace(urlTemplate);

    try {//from   w w w .j av a2 s.c  o m
        CredentialsProvider cp = new BasicCredentialsProvider();
        cp.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("jasperadmin", "jasperadmin"));
        CloseableHttpClient hc = HttpClientBuilder.create().setDefaultCredentialsProvider(cp).build();

        HttpGet getMethod = new HttpGet(url);
        getMethod.addHeader("accept", "application/pdf");
        HttpResponse res = hc.execute(getMethod);
        if (res.getStatusLine().getStatusCode() != 200) {
            throw new RuntimeException("Failed : HTTP eror code: " + res.getStatusLine().getStatusCode());
        }

        InputStream is = res.getEntity().getContent();
        OutputStream os = new FileOutputStream(new File("vencimientos.pdf"));
        int read = 0;
        byte[] bytes = new byte[2048];

        while ((read = is.read(bytes)) != -1) {
            os.write(bytes, 0, read);
        }
        is.close();
        os.close();

        if (Desktop.isDesktopSupported()) {
            File pdfFile = new File("vencimientos.pdf");
            Desktop.getDesktop().open(pdfFile);
        }

    } catch (IOException ex) {
        Logger.getLogger(SamplesUseHttpclient.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.apress.prospringintegration.transform.ToStringTransformer.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:string-transformer.xml");

    MessageChannel input = context.getBean("input", MessageChannel.class);
    PollableChannel output = context.getBean("output", PollableChannel.class);

    Map<String, String> customerMap = new HashMap<String, String>();
    customerMap.put("firstName", "John");
    customerMap.put("lastName", "Smith");
    customerMap.put("address", "100 State Street");
    customerMap.put("city", "Los Angeles");
    customerMap.put("state", "CA");
    customerMap.put("zip", "90064");

    System.out.println("toString(): " + customerMap.toString());

    Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build();
    input.send(message);// www .  j  a va2  s. c  o m

    Message<?> reply = output.receive();
    System.out.println("received: " + reply.getPayload());
}

From source file:com.apress.prospringintegration.transform.PayloadTypeTransformer.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:payload-type-transformer.xml");

    MessageChannel input = context.getBean("input", MessageChannel.class);
    PollableChannel output = context.getBean("output", PollableChannel.class);

    Map<String, String> customerMap = new HashMap<String, String>();
    customerMap.put("firstName", "John");
    customerMap.put("lastName", "Smith");
    customerMap.put("address", "100 State Street");
    customerMap.put("city", "Los Angeles");
    customerMap.put("state", "CA");
    customerMap.put("zip", "90064");

    Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build();
    input.send(message);//from  w ww.j a v a 2  s  .  com

    Message<?> reply = output.receive();
    System.out.println("received: " + reply.getPayload());
}

From source file:com.apress.prospringintegration.transform.SerializerTransformer.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:serializer-transformer.xml");

    MessageChannel input = context.getBean("input", MessageChannel.class);
    PollableChannel output = context.getBean("output", PollableChannel.class);

    Map<String, String> customerMap = new HashMap<String, String>();
    customerMap.put("firstName", "John");
    customerMap.put("lastName", "Smith");
    customerMap.put("address", "100 State Street");
    customerMap.put("city", "Los Angeles");
    customerMap.put("state", "CA");
    customerMap.put("zip", "90064");

    System.out.println("toString(): " + customerMap.toString());

    Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build();
    input.send(message);//from w w  w  .  j av  a 2  s. c  o  m

    Message<?> reply = output.receive();
    System.out.println("received: " + reply.getPayload());
}

From source file:com.apress.prospringintegration.claimcheck.ClaimCheckExample.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "/spring/claimcheck-context.xml");

    MessageChannel input = context.getBean("checkinChannel", MessageChannel.class);
    PollableChannel output = context.getBean("checkoutChannel", PollableChannel.class);

    Map<String, String> customerMap = new HashMap<String, String>();
    customerMap.put("firstName", "John");
    customerMap.put("lastName", "Smith");
    customerMap.put("address", "100 State Street");
    customerMap.put("city", "Los Angeles");
    customerMap.put("state", "CA");
    customerMap.put("zip", "90064");

    Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build();
    input.send(message);/*w w  w  . j a  v a 2 s .  co m*/

    Message<?> reply = output.receive();
    System.out.println("received: " + reply.getPayload());
}

From source file:com.apress.prospringintegration.transform.ProgrammaticHeaderEnricher.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:programmatic-header-enricher.xml");

    MessageChannel input = context.getBean("input", MessageChannel.class);
    PollableChannel output = context.getBean("output", PollableChannel.class);

    Map<String, String> customerMap = new HashMap<String, String>();
    customerMap.put("firstName", "John");
    customerMap.put("lastName", "Smith");
    customerMap.put("address", "100 State Street");
    customerMap.put("city", "Los Angeles");
    customerMap.put("state", "CA");
    customerMap.put("zip", "90064");

    Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build();
    input.send(message);//w w  w .  j a  v a2  s.com

    Message<?> reply = output.receive();
    System.out.println("received: " + reply);
}