List of usage examples for java.util Map get
V get(Object key);
From source file:Main.java
public static void main(String[] argv) throws Exception { final int MAX_ENTRIES = 100; Map cache = new LinkedHashMap(MAX_ENTRIES + 1, .75F, true) { public boolean removeEldestEntry(Map.Entry eldest) { return size() > MAX_ENTRIES; }//from w ww . j a va 2 s .c o m }; Object key = "key"; Object value = "value"; cache.put(key, value); Object o = cache.get(key); if (o == null && !cache.containsKey(key)) { } cache = (Map) Collections.synchronizedMap(cache); }
From source file:cn.dockerfoundry.ide.eclipse.dockerfile.validator.DockerfileDelegatingValidator.java
public static void main(String[] args) { InputStream dockerfileInputStream = DockerfileDelegatingValidator.class.getResourceAsStream("dockerfile"); DockerfileDelegatingValidator validator = new DockerfileDelegatingValidator(dockerfileInputStream); Map<DockerfileValidationLevel, List<DockerfileValidationResult>> result = validator.validate(); List<DockerfileValidationResult> infos = result.get(DockerfileValidationLevel.INFO); List<DockerfileValidationResult> errors = result.get(DockerfileValidationLevel.ERROR); List<DockerfileValidationResult> warnings = result.get(DockerfileValidationLevel.WARNING); System.out.println("infos:"); for (Iterator<DockerfileValidationResult> iterator = infos.iterator(); iterator.hasNext();) { DockerfileValidationResult validationResult = (DockerfileValidationResult) iterator.next(); System.out.println(validationResult); }//w w w . j av a 2s .c o m System.out.println("errors:"); for (Iterator<DockerfileValidationResult> iterator = errors.iterator(); iterator.hasNext();) { DockerfileValidationResult validationResult = (DockerfileValidationResult) iterator.next(); System.out.println(validationResult); } System.out.println("warnings:"); for (Iterator<DockerfileValidationResult> iterator = warnings.iterator(); iterator.hasNext();) { DockerfileValidationResult validationResult = (DockerfileValidationResult) iterator.next(); System.out.println(validationResult); } }
From source file:DiameterMap.java
public static void main(String args[]) { String names[] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto" }; float diameters[] = { 4800f, 12103.6f, 12756.3f, 6794f, 142984f, 120536f, 51118f, 49532f, 2274f }; Map map = new TreeMap(); for (int i = 0, n = names.length; i < n; i++) { map.put(names[i], new Float(diameters[i])); }/* www. jav a 2 s . c o m*/ Iterator it = map.keySet().iterator(); Object obj; while (it.hasNext()) { obj = it.next(); System.out.println(obj + ": " + map.get(obj)); } }
From source file:com.rabbitmq.examples.FileConsumer.java
public static void main(String[] args) { Options options = new Options(); options.addOption(new Option("h", "uri", true, "AMQP URI")); options.addOption(new Option("q", "queue", true, "queue name")); options.addOption(new Option("t", "type", true, "exchange type")); options.addOption(new Option("e", "exchange", true, "exchange name")); options.addOption(new Option("k", "routing-key", true, "routing key")); options.addOption(new Option("d", "directory", true, "output directory")); CommandLineParser parser = new GnuParser(); try {//from w ww.ja va 2 s. c om CommandLine cmd = parser.parse(options, args); String uri = strArg(cmd, 'h', "amqp://localhost"); String requestedQueueName = strArg(cmd, 'q', ""); String exchangeType = strArg(cmd, 't', "direct"); String exchange = strArg(cmd, 'e', null); String routingKey = strArg(cmd, 'k', null); String outputDirName = strArg(cmd, 'd', "."); File outputDir = new File(outputDirName); if (!outputDir.exists() || !outputDir.isDirectory()) { System.err.println("Output directory must exist, and must be a directory."); System.exit(2); } ConnectionFactory connFactory = new ConnectionFactory(); connFactory.setUri(uri); Connection conn = connFactory.newConnection(); final Channel ch = conn.createChannel(); String queueName = (requestedQueueName.equals("") ? ch.queueDeclare() : ch.queueDeclare(requestedQueueName, false, false, false, null)).getQueue(); if (exchange != null || routingKey != null) { if (exchange == null) { System.err.println("Please supply exchange name to bind to (-e)"); System.exit(2); } if (routingKey == null) { System.err.println("Please supply routing key pattern to bind to (-k)"); System.exit(2); } ch.exchangeDeclare(exchange, exchangeType); ch.queueBind(queueName, exchange, routingKey); } QueueingConsumer consumer = new QueueingConsumer(ch); ch.basicConsume(queueName, consumer); while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); Map<String, Object> headers = delivery.getProperties().getHeaders(); byte[] body = delivery.getBody(); Object headerFilenameO = headers.get("filename"); String headerFilename = (headerFilenameO == null) ? UUID.randomUUID().toString() : headerFilenameO.toString(); File givenName = new File(headerFilename); if (givenName.getName().equals("")) { System.out.println("Skipping file with empty name: " + givenName); } else { File f = new File(outputDir, givenName.getName()); System.out.print("Writing " + f + " ..."); FileOutputStream o = new FileOutputStream(f); o.write(body); o.close(); System.out.println(" done."); } ch.basicAck(delivery.getEnvelope().getDeliveryTag(), false); } } catch (Exception ex) { System.err.println("Main thread caught exception: " + ex); ex.printStackTrace(); System.exit(1); } }
From source file:net.itransformers.bgpPeeringMap.BgpPeeringMapFromFile.java
public static void main(String[] args) throws Exception { Map<String, String> params = CmdLineParser.parseCmdLine(args); logger.info("input params" + params.toString()); final String settingsFile = params.get("-s"); if (settingsFile == null) { printUsage("bgpPeeringMap.properties"); return;//from w w w . j a v a2 s .c o m } Map<String, String> settings = loadProperties(new File(System.getProperty("base.dir"), settingsFile)); logger.info("Settings" + settings.toString()); File outputDir = new File(System.getProperty("base.dir"), settings.get("output.dir")); System.out.println(outputDir.getAbsolutePath()); boolean result = outputDir.mkdir(); // if (!result) { // System.out.println("result:"+result); // System.out.println("Unable to create dir: "+outputDir); // return; // } File graphmlDir = new File(outputDir, settings.get("output.dir.graphml")); result = outputDir.mkdir(); // if (!result) { // System.out.println("Unable to create dir: "+graphmlDir); // return; // } XsltTransformer transformer = new XsltTransformer(); byte[] rawData = readRawDataFile(settings.get("raw-data-file")); logger.info("First-transformation has started with xsltTransformator " + settings.get("xsltFileName1")); ByteArrayOutputStream outputStream1 = new ByteArrayOutputStream(); File xsltFileName1 = new File(System.getProperty("base.dir"), settings.get("xsltFileName1")); ByteArrayInputStream inputStream1 = new ByteArrayInputStream(rawData); // transformer.transformXML(inputStream1, xsltFileName1, outputStream1, settings); logger.info("First transformation finished"); File outputFile1 = new File(graphmlDir, "bgpPeeringMap-intermediate.xml"); FileUtils.writeStringToFile(outputFile1, new String(outputStream1.toByteArray())); logger.info("Second transformation started with xsltTransformator " + settings.get("xsltFileName2")); ByteArrayOutputStream outputStream2 = new ByteArrayOutputStream(); File xsltFileName2 = new File(System.getProperty("base.dir"), settings.get("xsltFileName2")); ByteArrayInputStream inputStream2 = new ByteArrayInputStream(outputStream1.toByteArray()); // transformer.transformXML(inputStream2, xsltFileName2, outputStream2, settings); logger.info("Second transformation finished"); File outputFile = new File(graphmlDir, "bgpPeeringMap.graphml"); File nodesFileListFile = new File(graphmlDir, "nodes-file-list.txt"); FileUtils.writeStringToFile(outputFile, new String(outputStream2.toByteArray())); logger.info("Output Graphml saved in a file in" + graphmlDir); FileUtils.writeStringToFile(nodesFileListFile, "bgpPeeringMap.graphml"); ByteArrayInputStream inputStream3 = new ByteArrayInputStream(outputStream2.toByteArray()); ByteArrayOutputStream outputStream3 = new ByteArrayOutputStream(); File xsltFileName3 = new File(System.getProperty("base.dir"), settings.get("xsltFileName3")); // transformer.transformXML(inputStream3, xsltFileName3, outputStream3); }
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();// w w w .ja v a 2 s. c om Object value = map.get(key); } }
From source file:com.base.httpclient.HttpJsonClient.java
public static void main(String[] args) throws ClientProtocolException, IOException, URISyntaxException { String rdStr = RandomStringUtils.randomNumeric(9); log.info(rdStr);/* w w w.j a v a 2 s . co m*/ EqualsBuilder eb = new EqualsBuilder(); String url = "http://detailskip.taobao.com/json/ifq.htm?id=18278375481&sid=" + rdStr + "&q=1"; String jsonStr = HttpJsonClient.get(url, null); String str = StringUtilsExtends.substringBetween(jsonStr, ":{", "}"); Map<String, Integer> map = JsonUtil.getMap4Json("{" + str + "}"); log.info(map.get("quanity") + ""); }
From source file:de.ingrid.iplug.AdminServer.java
/** * To start the admin web server from the commandline. * @param args The server port and the web app folder. * @throws Exception Something goes wrong. *//*from w w w .ja v a 2s .c o m*/ public static void main(String[] args) throws Exception { String usage = "<serverPort> <webappFolder>"; if ((args.length == 0) && (args.length != 4) && (args.length != 6)) { System.err.println(usage); return; } Map arguments = readParameters(args); File plugDescriptionFile = new File(PLUG_DESCRIPTION); if (arguments.containsKey("--plugdescription")) { plugDescriptionFile = new File((String) arguments.get("--plugdescription")); } File communicationProperties = new File(COMMUNICATION_PROPERTES); if (arguments.containsKey("--descriptor")) { communicationProperties = new File((String) arguments.get("--descriptor")); } int port = Integer.parseInt(args[0]); File webFolder = new File(args[1]); //push init params for all contexts (e.g. step1 and step2) HashMap hashMap = new HashMap(); hashMap.put("plugdescription.xml", plugDescriptionFile.getAbsolutePath()); hashMap.put("communication.xml", communicationProperties.getAbsolutePath()); WebContainer container = startWebContainer(hashMap, port, webFolder, false, null); container.join(); }
From source file:com.khartec.waltz.jobs.AuthSourceHarness.java
public static void main(String[] args) { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class); AuthoritativeSourceCalculator authoritativeSourceCalculator = ctx .getBean(AuthoritativeSourceCalculator.class); long CTO_OFFICE = 40; long CTO_ADMIN = 400; long CEO_OFFICE = 10; long CIO_OFFICE = 20; long MARKET_RISK = 220; long CREDIT_RISK = 230; long OPERATIONS_IT = 200; long RISK = 210; long orgUnitId = CIO_OFFICE; authoritativeSourceCalculator.calculateAuthSourcesForOrgUnitTree(orgUnitId); long st = System.currentTimeMillis(); for (int i = 0; i < 100; i++) { authoritativeSourceCalculator.calculateAuthSourcesForOrgUnitTree(orgUnitId); }//from w ww.j a v a2 s . c om long end = System.currentTimeMillis(); System.out.println("DUR " + (end - st)); Map<Long, Map<String, Map<Long, AuthoritativeSource>>> rulesByOrgId = authoritativeSourceCalculator .calculateAuthSourcesForOrgUnitTree(orgUnitId); System.out.println("--CIO---"); AuthoritativeSourceCalculator.prettyPrint(rulesByOrgId.get(CIO_OFFICE)); System.out.println("--RISK---"); AuthoritativeSourceCalculator.prettyPrint(rulesByOrgId.get(RISK)); System.out.println("--MARKETRISK---"); AuthoritativeSourceCalculator.prettyPrint(rulesByOrgId.get(MARKET_RISK)); System.out.println("--OPS---"); AuthoritativeSourceCalculator.prettyPrint(rulesByOrgId.get(OPERATIONS_IT)); System.out.println("--CREDIT RISK---"); AuthoritativeSourceCalculator.prettyPrint(rulesByOrgId.get(CREDIT_RISK)); }
From source file:com.act.lcms.db.io.LoadStandardIonAnalysisTableIntoDB.java
public static void main(String[] args) throws Exception { Options opts = new Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build());/*from ww w .j ava 2 s . co m*/ } CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { System.err.format("Argument parsing failed: %s\n", e.getMessage()); HELP_FORMATTER.printHelp(LoadStandardIonAnalysisTableIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption("help")) { HELP_FORMATTER.printHelp(LoadStandardIonAnalysisTableIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); return; } File inputFile = new File(cl.getOptionValue(OPTION_FILE_PATH)); if (!inputFile.exists()) { System.err.format("Unable to find input file at %s\n", cl.getOptionValue(OPTION_FILE_PATH)); new HelpFormatter().printHelp(LoadConstructAnalysisTableIntoDB.class.getCanonicalName(), opts, true); System.exit(1); } try (DB db = DB.openDBFromCLI(cl)) { db.getConn().setAutoCommit(false); TSVParser parser = new TSVParser(); parser.parse(inputFile); for (Map<String, String> row : parser.getResults()) { Integer standardIonResultId = Integer.parseInt(row.get( ExportStandardIonResultsFromDB.STANDARD_ION_HEADER_FIELDS.STANDARD_ION_RESULT_ID.name())); String dbValueOfMetlinIon = ExportStandardIonResultsFromDB.NULL_VALUE; StandardIonResult ionResult = StandardIonResult.getInstance().getById(db, standardIonResultId); if (ionResult.getManualOverrideId() != null) { // There is an existing manual override ion in the DB CuratedStandardMetlinIon curatedChemical = CuratedStandardMetlinIon.getBestMetlinIon(db, ionResult.getManualOverrideId()); dbValueOfMetlinIon = curatedChemical.getBestMetlinIon(); } String manualPickOfMetlinIon = row .get(ExportStandardIonResultsFromDB.STANDARD_ION_HEADER_FIELDS.MANUAL_PICK.name()); // If the manual metlin ion pick row is not NULL and it is not the same as the value stored in the DB, then // we need to add a new entry to the curated metlin ion table. if (!manualPickOfMetlinIon.equals(ExportStandardIonResultsFromDB.NULL_VALUE) && !manualPickOfMetlinIon.equals(dbValueOfMetlinIon)) { System.out.format("Manual override has been found, so updating the DB\n"); // A manual entry was created. if (!MS1.VALID_MS1_IONS.contains(manualPickOfMetlinIon)) { System.err.format("ERROR: found invalid chemical name: %s\n", manualPickOfMetlinIon); System.exit(-1); } String note = row.get(ExportStandardIonResultsFromDB.STANDARD_ION_HEADER_FIELDS.NOTE.name()); CuratedStandardMetlinIon result = CuratedStandardMetlinIon.insertCuratedStandardMetlinIonIntoDB( db, LocalDateTime.now(CuratedStandardMetlinIon.utcDateTimeZone), cl.getOptionValue(OPTION_AUTHOR), manualPickOfMetlinIon, note, standardIonResultId); if (result == null) { System.err.format( "WARNING: Could not insert curated entry to the curated metlin ion table\n", manualPickOfMetlinIon); System.exit(-1); } else { StandardIonResult getIonResult = StandardIonResult.getInstance().getById(db, standardIonResultId); getIonResult.setManualOverrideId(result.getId()); if (!StandardIonResult.getInstance().update(db, getIonResult)) { System.err.format( "WARNING: Could not insert manual override id to the standard ion table\n", manualPickOfMetlinIon); System.exit(-1); } else { System.out.format( "Successfully committed updates to the standard ion table and the curated metlin ion table\n"); } } } } db.getConn().commit(); } }