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:MainClass.java

public static void main(String[] args) throws Exception {
    PdfReader reader = new PdfReader("2.pdf");
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("3.pdf"));
    AcroFields form = stamper.getAcroFields();
    HashMap fields = form.getFields();
    AcroFields.Item field = (AcroFields.Item) fields.get("PushMe");
    PRIndirectReference ref = (PRIndirectReference) field.widget_refs.iterator().next();
    PdfDictionary object = (PdfDictionary) reader.getPdfObject(ref.getNumber());
    PdfDictionary action = (PdfDictionary) object.get(PdfName.A);
    PdfDictionary file = (PdfDictionary) action.get(PdfName.F);
    file.put(PdfName.F, new PdfString("http://yourserver/form.jsp"));
    stamper.close();/*from w w  w .j a v a 2 s .  c om*/

}

From source file:Main.java

public static void main(String[] args) {
    HashMap<String, int[]> h = new HashMap<String, int[]>();
    h.put("PID", new int[] { 1, 2 });

    System.out.println(h.get("PID")[0]);
    System.out.println(h.get("PID")[1]);
}

From source file:to.sparks.mtgox.example.HowToWithdrawBitcoins.java

/** *
 * Send the entire bitcoin balance of a MtGox account to a destination
 * bitcoin address./*from   w  ww.j  a v  a2s  .  com*/
 * OTP is not supported! Please turn off Yubikey/OTP
 *
 * @param args The destination bitcoin address
 * @throws Exception OTP is not supported! Please turn off Yubikey/OTP
 */
public static void main(String[] args) throws Exception {

    // Obtain a $USD instance of the API
    ApplicationContext context = new ClassPathXmlApplicationContext("to/sparks/mtgox/example/Beans.xml");
    MtGoxHTTPClient mtGoxAPI = (MtGoxHTTPClient) context.getBean("mtgoxUSD");

    HashMap<String, Wallet> wallets = mtGoxAPI.getAccountInfo().getWallets();
    Wallet btcWallet = wallets.get("BTC");
    MtGoxBitcoin mtgoxBalance = (MtGoxBitcoin) btcWallet.getBalance();
    logger.log(Level.INFO, "MtGox account balance: BTC {0}", mtgoxBalance.toPlainString());
    if (mtgoxBalance.compareTo(BigDecimal.ZERO) > 0) {

        MtGoxBitcoin fee = new MtGoxBitcoin(0.0005D); // Transaction fee
        MtGoxBitcoin transferAmount = new MtGoxBitcoin(mtgoxBalance.subtract(fee));

        if (transferAmount.compareTo(BigDecimal.ZERO) > 0) {
            logger.log(Level.INFO, "Transferring BTC {0} to bitcoin address {1} and paying fee {2}",
                    new Object[] { transferAmount.toPlainString(), args[0], fee.toPlainString() });
            SendBitcoinsTransaction trx = mtGoxAPI.sendBitcoins(args[0], transferAmount, fee, true, false);
            logger.log(Level.INFO, "Transfer success.  trx: {0}", trx.getTrx());
        }
    }
}

From source file:foldersync.FolderSync.java

/**
 * @param args the command line arguments
 *//*from ww w . j av a 2s  . co  m*/
public static void main(String[] args) {
    // TODO code application logic here
    //JSONParser parser = new JSONParser();

    try {
        Options options = new Options(args[0]);
        List<HashMap> watchList = options.watchesList();
        while (true) {
            for (HashMap watch : watchList) {
                // System.out.println(watch);
                Sync sync = new Sync((String) watch.get("sourceDir"), (String) watch.get("destDir"),
                        (List) watch.get("watch"), (List) watch.get("dontwatch"));
                sync.syncFolders();
            }
            Thread.sleep(100);
        }
    } catch (IOException e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    } catch (ParseException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    MyKey e1 = new MyKey(1);
    MyKey e2 = new MyKey(2);

    HashMap<MyKey, Integer> map = new HashMap<>();
    map.put(e1, 1);/*w w w  .ja va  2 s  .  co  m*/
    map.put(e2, 2);

    System.out.println(map.get(e1));
    System.out.println(map);

    e1.setValue(9);
    System.out.println(map.get(e1));
    System.out.println(map);

    e1.setValue(2);
    System.out.println(map.get(e1));
    System.out.println(map);

    MyKey e3 = new MyKey(2);
    System.out.println(map.get(e3));
}

From source file:Main.java

public static void main(String args[]) {
    HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();

    map.put(1, 2);//from  w w  w.j ava 2 s  . c om
    map.put(2, 3);
    map.put(3, 4);

    for (Integer key : map.keySet()) {
        System.out.println(map.get(key));
    }
}

From source file:HashDemoGeneric.java

public static void main(String[] args) {
    HashMap<Integer, String> map = new HashMap<Integer, String>();

    map.put(1, "Ian");
    map.put(42, "Scott");
    map.put(123, "Somebody else");

    String name = map.get(42);
    System.out.println(name);//www  . j  a v a 2s .c  o  m
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    MyPdfPageEventHelper tracker = new MyPdfPageEventHelper();
    writer.setPageEvent(tracker);/* w ww. j a v  a2  s . co  m*/
    document.open();
    document.add(createParagraph("Fox", "Hello lazy dog."));

    document.newPage();
    HashMap lines = tracker.getLines();
    for (Iterator i = lines.keySet().iterator(); i.hasNext();) {
        String speaker = (String) i.next();
        Integer count = (Integer) lines.get(speaker);
        document.add(new Paragraph(speaker + ": " + count.intValue() + " lines."));
    }
    document.close();
}

From source file:TasteOfThingsV1.java

 public static void main(String args[]) throws Exception {
   prepareData();/*from w  ww  . jav  a 2 s. c  o  m*/

   HashBag myBag = new HashBag(testMap.values());

   System.err.println("How many Boxes? " + myBag.getCount("Boxes"));
   myBag.add("Boxes", 5);
   System.err.println("How many Boxes now? " + myBag.getCount("Boxes"));

   Method method =
     testBean.getClass().getDeclaredMethod("getTestMap", new Class[0]);
   HashMap reflectionMap =
     (HashMap)method.invoke(testBean, new Object[0]);
   System.err.println("The value of the 'squ' key using reflection: " +
     reflectionMap.get("squ"));

   String squ = BeanUtils.getMappedProperty(testBean, "testMap", "squ");
   squ = StringUtils.capitalize(squ);

   PropertyUtils.setMappedProperty(testBean, "testMap", "squ", squ);

   System.err.println("The value of the 'squ' key is: " +
     BeanUtils.getMappedProperty(testBean, "testMap", "squ"));

   String box = (String)testMap.get("box");
   String caps =
     Character.toTitleCase(box.charAt(0)) +
     box.substring(1, box.length());
   System.err.println("Capitalizing boxes by Java: " + caps);
}

From source file:Main.java

public static void main(String[] args) {
    ReferenceQueue referenceQueue = new ReferenceQueue();
    Object object = new Object() {
        public String toString() {
            return "Referenced Object";
        }/*from  w  w  w.  ja v a 2  s . co  m*/
    };
    Object data = new Object() {
        public String toString() {
            return "Data";
        }
    };

    HashMap map = new HashMap();
    Reference reference = new SoftReference(object, referenceQueue);

    map.put(reference, data);

    System.out.println(reference.get());
    System.out.println(map.get(reference));
    System.out.println(reference.isEnqueued());

    System.gc();
    System.out.println(reference.get());
    System.out.println(map.get(reference));
    System.out.println(reference.isEnqueued());

    object = null;
    data = null;

    System.gc();
    System.out.println(reference.get());
    System.out.println(map.get(reference));
    System.out.println(reference.isEnqueued());
}