Example usage for java.util Map get

List of usage examples for java.util Map get

Introduction

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

Prototype

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

  public static void main(String args[]) throws Exception {
    BeanUtilsExampleV4 diff = new BeanUtilsExampleV4();
    Actor actor = diff.prepareData();/*  w  ww.  ja  v  a2 s .  co  m*/

    ConvertUtilsBean convertUtilsBean = new ConvertUtilsBean();
    convertUtilsBean.deregister(String.class);
    convertUtilsBean.register(new MyStringConverter(), String.class);

    convertUtilsBean.deregister(Long.class);
    convertUtilsBean.register(new MyLongConverter(), Long.class);
    convertUtilsBean.register(new MyLongConverter(), Long.TYPE);

    BeanUtilsBean beanUtilsBean =
      new BeanUtilsBean(convertUtilsBean, new PropertyUtilsBean());

    System.err.println("==== Values before calling describe ==== ");
    System.err.println("By PropertyUtils: " +
      PropertyUtils.getProperty(actor, "name"));
    System.err.println("By BeanUtils: " +
      beanUtilsBean.getProperty(actor, "name"));
    System.err.println(beanUtilsBean.getProperty(actor, "worth"));

    Map describedData = beanUtilsBean.describe(actor);

    // check the map
    System.err.println("==== Values in Map ==== ");
    System.err.println(describedData.get("name"));
    System.err.println(describedData.get("worth"));

    // create a new Actor Bean
    Actor newActor = new Actor();
    beanUtilsBean.populate(newActor, describedData);

    System.err.println("==== Values after calling populate ==== ");
    System.err.println(beanUtilsBean.getProperty(newActor, "name"));
    System.err.println(beanUtilsBean.getProperty(newActor, "worth"));

}

From source file:com.stratio.streaming.StreamingEngine.java

public static void main(String[] args) {
    try (AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(
            BaseConfiguration.class)) {

        annotationConfigApplicationContext.registerShutdownHook();

        Map<String, JavaStreamingContext> contexts = annotationConfigApplicationContext
                .getBeansOfType(JavaStreamingContext.class);

        for (JavaStreamingContext context : contexts.values()) {
            context.start();// ww w. j  a va2s.  co m
            log.info("Started context {}", context.sparkContext().appName());
        }
        contexts.get("actionContext").awaitTermination();
    } catch (Exception e) {
        log.error("Fatal error", e);
    }
}

From source file:Main.java

public static void main(String[] args) {
    Map<Integer, Integer> data = new HashMap<Integer, Integer>();
    data.put(10, 2);/*from  w w  w  .j a va 2  s . c o  m*/
    data.put(20, 3);
    data.put(30, 5);
    data.put(40, 15);
    data.put(50, 4);

    SortedSet<Integer> keys = new TreeSet<Integer>(data.keySet());
    String s = "";
    for (Integer key : keys) {
        s += key + " : ";
        for (int i = 0; i < data.get(key); i++) {
            s += "*";
        }
        s += "\n";
    }
    System.out.println(s);
}

From source file:example.Main.java

public static void main(String[] args) throws Exception {
    Class[] classes = new Class[3];
    classes[0] = A.class;
    classes[1] = B.class;
    classes[2] = C.class;

    JAXBContext jc = JAXBContext.newInstance(classes);

    JAXBIntrospector ji = jc.createJAXBIntrospector();
    Map<QName, Class> classByQName = new HashMap<QName, Class>(classes.length);
    for (Class clazz : classes) {
        QName qName = ji.getElementName(clazz.newInstance());
        if (null != qName) {
            classByQName.put(qName, clazz);
        }//from   ww  w. ja v  a 2s.  c o  m
    }

    QName qName = new QName("http://www.example.com", "EH");
    System.out.println(classByQName.get(qName));
}

From source file:io.s4.comm.util.JSONUtil.java

public static void main(String[] args) {
    Map<String, Object> outerMap = new HashMap<String, Object>();

    outerMap.put("doubleValue", 0.3456d);
    outerMap.put("integerValue", 175647);
    outerMap.put("longValue", 0x0000005000067000l);
    outerMap.put("stringValue", "Hello there");

    Map<String, Object> innerMap = null;
    List<Map<String, Object>> innerList1 = new ArrayList<Map<String, Object>>();

    innerMap = new HashMap<String, Object>();
    innerMap.put("name", "kishore");
    innerMap.put("count", 1787265);
    innerList1.add(innerMap);/*from  w w w  .  j a va2  s .co m*/
    innerMap = new HashMap<String, Object>();
    innerMap.put("name", "fred");
    innerMap.put("count", 11);
    innerList1.add(innerMap);

    outerMap.put("innerList1", innerList1);

    List<Integer> innerList2 = new ArrayList<Integer>();
    innerList2.add(65);
    innerList2.add(2387894);
    innerList2.add(456);

    outerMap.put("innerList2", innerList2);

    JSONObject jsonObject = toJSONObject(outerMap);

    String flatJSONString = null;
    try {
        System.out.println(jsonObject.toString(3));
        flatJSONString = jsonObject.toString();
        Object o = jsonObject.get("innerList1");
        if (!(o instanceof JSONArray)) {
            System.out.println("Unexpected type of list " + o.getClass().getName());
        } else {
            JSONArray jsonArray = (JSONArray) o;
            o = jsonArray.get(0);
            if (!(o instanceof JSONObject)) {
                System.out.println("Unexpected type of map " + o.getClass().getName());
            } else {
                JSONObject innerJSONObject = (JSONObject) o;
                System.out.println(innerJSONObject.get("name"));
            }
        }
    } catch (JSONException je) {
        je.printStackTrace();
    }

    if (!flatJSONString.equals(toJsonString(outerMap))) {
        System.out.println("JSON strings don't match!!");
    }

    Map<String, Object> map = getMapFromJson(flatJSONString);

    Object o = map.get("doubleValue");
    if (!(o instanceof Double)) {
        System.out.println("Expected type Double, got " + o.getClass().getName());
        Double doubleValue = (Double) o;
        if (doubleValue != 0.3456d) {
            System.out.println("Expected 0.3456, got " + doubleValue);
        }
    }

    o = map.get("innerList1");
    if (!(o instanceof List)) {
        System.out.println("Expected implementation of List, got " + o.getClass().getName());
    } else {
        List innerList = (List) o;
        o = innerList.get(0);
        if (!(o instanceof Map)) {
            System.out.println("Expected implementation of Map, got " + o.getClass().getName());
        } else {
            innerMap = (Map) o;
            System.out.println(innerMap.get("name"));
        }
    }
    System.out.println(map);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Map<String, List<String>> fontFaceNames = new HashMap<String, List<String>>();
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = ge.getAllFonts();

    for (int i = 0; i < fonts.length; i++) {
        String familyName = fonts[i].getFamily();
        String faceName = fonts[i].getName();

        List<String> list = fontFaceNames.get(familyName);
        if (list == null) {
            list = new ArrayList<String>();
            fontFaceNames.put(familyName, list);
        }//from w  w  w .j  av a2  s.c om
        list.add(faceName);
    }
    System.out.println(fontFaceNames);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Object keyObject = "";
    Object valueObject = "";
    Map<Object, Object> weakMap = new WeakHashMap<Object, Object>();

    weakMap.put(keyObject, valueObject);
    WeakReference weakValue = new WeakReference<Object>(valueObject);

    weakMap.put(keyObject, weakValue);/*from w w  w.ja  v  a2  s. co m*/

    Iterator it = weakMap.keySet().iterator();
    while (it.hasNext()) {
        Object key = it.next();
        weakValue = (WeakReference) weakMap.get(key);
        if (weakValue == null) {
            System.out.println("Value has been garbage-collected");
        } else {
            System.out.println("Get value");
            valueObject = weakValue.get();
        }
    }
}

From source file:com.facebook.infrastructure.net.io.TcpReader.java

public static void main(String[] args) throws Throwable {
    Map<TcpReaderState, StartState> stateMap = new HashMap<TcpReaderState, StartState>();
    stateMap.put(TcpReaderState.CONTENT, new ContentState(null, 10));
    stateMap.put(TcpReaderState.START, new ProtocolState(null));
    stateMap.put(TcpReaderState.CONTENT_LENGTH, new ContentLengthState(null));

    StartState state = stateMap.get(TcpReaderState.CONTENT);
    System.out.println(state.getClass().getName());
    state = stateMap.get(TcpReaderState.CONTENT_LENGTH);
    System.out.println(state.getClass().getName());
}

From source file:com.qcloud.project.macaovehicle.util.MessageGetter.java

public static void main(String[] args) throws Exception {

    // StringBuilder stringBuilder = new StringBuilder();
    // stringBuilder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><auditData><url>vehicle</url><success>0</success><vehicle><ric>1000001</ric><reason></reason><state>1</state></vehicle></auditData>");
    // System.out.println(stringBuilder.toString());
    // String dataPostURL = "http://120.25.12.206:8888/DeclMsg/Ciq";
    // MessageGetter.sendXml(stringBuilder.toString(), dataPostURL);
    Map<String, Object> param = new LinkedHashMap<String, Object>();
    param.put("driverIc", "C09000000002a6d32701");
    param.put("driverName", "");
    param.put("sex", "1");
    param.put("birthday", "1991-09-01T00:00:00");
    param.put("nationality", "");
    param.put("corpName", "??");
    param.put("registerNo", "C0900000000347736701");
    param.put("drivingValidityDate", "2017-04-17T09:00:00");
    param.put("commonFlag", "1");
    param.put("residentcardValidityDate", "2014-04-27T09:00:00");
    param.put("leftHandFingerprint", "1");
    param.put("rightHandFingerprint", "2");
    param.put("imageEignvalues", "3");
    param.put("certificateNo", "4");
    param.put("validityEndDate", "2020-04-17T09:00:00");
    param.put("creator", "");
    param.put("createDate", "2014-04-17T09:00:00");
    param.put("modifier", "");
    param.put("modifyDate", "2014-04-17T09:00:00");
    param.put("cityCode", "");
    param.put("nation", "?");
    param.put("tel", "13568877897");
    param.put("visaCode", "21212121");
    param.put("subscriberCode", "7937");
    param.put("visaValidityDate", "2017-04-17T09:00:00");
    param.put("icCode", "TDriver000018950");
    param.put("toCountry", "");
    param.put("fromCountry", "");
    param.put("licenseCode", "168819");
    param.put("idCard", "440882199110254657");
    param.put("secondName", "");
    param.put("secondBirthday", "1991-04-17T09:00:00");
    param.put("secondCertificateNo", "123456789");
    param.put("secondCertificateType", "03");
    param.put("visaNo", "123456789");
    param.put("stayPeriod", "180");
    param.put("residentcardValidityDate", "2017-04-27T09:00:00");
    param.put("returnCardNo", "123456789");
    param.put("pass", "123456789");
    param.put("drivingLicense", "422801197507232815");
    param.put("customCode", "12345");
    param.put("visaCity", "?");
    param.put("certificateType", "01");
    param.put("certificateCode", "12345678");
    param.put("subscribeDate", "2010-04-17T09:00:00");
    param.put("passportNo", "G20961897");
    param.put("transactType", "01");
    param.put("isAvoidInspect", "N");
    param.put("isPriorityInspect", "N");
    param.put("remark", "");
    String picSourcePath1 = "H://images/?.jpg";
    // String picSourcePath1="H://images/1/1.jpg";
    String picSourcePath2 = "H://images/1/2.jpeg";
    String picSourcePath3 = "H://images/1/3.jpeg";
    String picSourcePath4 = "H://images/1/4.jpeg";
    String picSourcePath5 = "H://images/1/5.jpeg";
    String picSourcePath6 = "H://images/1/6.jpeg";
    param.put("driverPhoto", Base64PicUtil.GetImageStr(picSourcePath1));
    // param.put("imageA", Base64PicUtil.GetImageStr(picSourcePath2));
    // param.put("imageB", Base64PicUtil.GetImageStr(picSourcePath3));
    // param.put("imageC", Base64PicUtil.GetImageStr(picSourcePath4));
    // param.put("imageD", Base64PicUtil.GetImageStr(picSourcePath5));
    String dataStr = MessageGetter.sendMessage(param, "driver", dataPostURL);
    Map<String, Object> map = XmlParseUtils.XmlToMap(dataStr);
    System.out.println(dataStr);/*  w  w  w  .j a  v  a 2s. co  m*/
    if (map.containsKey("message")) {
        String message = (String) map.get("message");
        if (message.equals("true")) {
            System.out.println("===================================================");
            System.out.println(map);
        }
    }
    System.out.println(dataStr);
}

From source file:com.joliciel.talismane.en.TalismaneEnglish.java

/**
 * @param args//from  w  ww.j  a va 2 s  . com
 * @throws Exception 
 */
public static void main(String[] args) throws Exception {
    Map<String, String> argsMap = StringUtils.convertArgs(args);
    CorpusFormat corpusReaderType = null;

    if (argsMap.containsKey("corpusReader")) {
        corpusReaderType = CorpusFormat.valueOf(argsMap.get("corpusReader"));
        argsMap.remove("corpusReader");
    }

    Extensions extensions = new Extensions();
    extensions.pluckParameters(argsMap);

    String sessionId = "";
    TalismaneServiceLocator locator = TalismaneServiceLocator.getInstance(sessionId);
    TalismaneService talismaneService = locator.getTalismaneService();
    TalismaneEnglish talismaneEnglish = new TalismaneEnglish(sessionId);

    TalismaneConfig config = talismaneService.getTalismaneConfig(argsMap, talismaneEnglish);
    if (config.getCommand() == null)
        return;

    if (corpusReaderType != null) {
        if (corpusReaderType == CorpusFormat.pennDep) {
            PennDepReader corpusReader = new PennDepReader(config.getReader());
            corpusReader.setParserService(config.getParserService());
            corpusReader.setPosTaggerService(config.getPosTaggerService());
            corpusReader.setTokeniserService(config.getTokeniserService());
            corpusReader.setTokenFilterService(config.getTokenFilterService());
            corpusReader.setTalismaneService(config.getTalismaneService());

            corpusReader.setPredictTransitions(config.isPredictTransitions());

            config.setParserCorpusReader(corpusReader);
            config.setPosTagCorpusReader(corpusReader);
            config.setTokenCorpusReader(corpusReader);
            config.setSentenceCorpusReader(corpusReader);

            corpusReader.setRegex(DEFAULT_CONLL_REGEX);

            if (config.getInputRegex() != null) {
                corpusReader.setRegex(config.getInputRegex());
            }

            if (config.getCommand().equals(Command.compare)) {
                File evaluationFile = new File(config.getEvaluationFilePath());
                ParserRegexBasedCorpusReader evaluationReader = config.getParserService()
                        .getRegexBasedCorpusReader(evaluationFile, config.getInputCharset());
                config.setParserEvaluationCorpusReader(evaluationReader);
                config.setPosTagEvaluationCorpusReader(evaluationReader);

                evaluationReader.setRegex(DEFAULT_CONLL_REGEX);

                if (config.getInputRegex() != null) {
                    evaluationReader.setRegex(config.getInputRegex());
                }
            }
        } else {
            throw new TalismaneException("Unknown corpusReader: " + corpusReaderType);
        }
    }
    Talismane talismane = config.getTalismane();

    extensions.prepareCommand(config, talismane);

    talismane.process();
}