List of usage examples for java.util Map put
V put(K key, V value);
From source file:fr.inria.atlanmod.atl_mr.utils.NeoEMFHBaseMigrator.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input file, both of xmi and zxmi extensions are supported"); inputOpt.setArgs(1);/*w ww. ja v a 2s. c o m*/ inputOpt.setRequired(true); Option outputOpt = OptionBuilder.create(OUT); outputOpt.setArgName("OUTPUT"); outputOpt.setDescription("Output HBase resource URI"); outputOpt.setArgs(1); outputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(E_PACKAGE); inClassOpt.setArgName("METAMODEL"); inClassOpt.setDescription("URI of the ecore Metamodel"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); options.addOption(inputOpt); options.addOption(outputOpt); options.addOption(inClassOpt); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); URI sourceUri = URI.createFileURI(commandLine.getOptionValue(IN)); URI targetUri = URI.createURI(commandLine.getOptionValue(OUT)); URI metamodelUri = URI.createFileURI(commandLine.getOptionValue(E_PACKAGE)); NeoEMFHBaseMigrator.class.getClassLoader().loadClass(commandLine.getOptionValue(E_PACKAGE)) .getMethod("init").invoke(null); //org.eclipse.gmt.modisco.java.kyanos.impl.JavaPackageImpl.init(); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("zxmi", new XMIResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put(KyanosURI.KYANOS_HBASE_SCHEME, KyanosResourceFactory.eINSTANCE); //Registering the metamodel // Resource MMResource = resourceSet.createResource(metamodelUri); // MMResource.load(Collections.EMPTY_MAP); // ATLMRUtils.registerPackages(resourceSet, MMResource); //Loading the XMI resource Resource sourceResource = resourceSet.createResource(sourceUri); Map<String, Object> loadOpts = new HashMap<String, Object>(); if ("zxmi".equals(sourceUri.fileExtension())) { loadOpts.put(XMIResource.OPTION_ZIP, Boolean.TRUE); } Runtime.getRuntime().gc(); long initialUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); LOG.log(Level.INFO, MessageFormat.format("Used memory before loading: {0}", ATLMRUtils.byteCountToDisplaySize(initialUsedMemory))); LOG.log(Level.INFO, "Loading source resource"); sourceResource.load(loadOpts); LOG.log(Level.INFO, "Source resource loaded"); Runtime.getRuntime().gc(); long finalUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); LOG.log(Level.INFO, MessageFormat.format("Used memory after loading: {0}", ATLMRUtils.byteCountToDisplaySize(finalUsedMemory))); LOG.log(Level.INFO, MessageFormat.format("Memory use increase: {0}", ATLMRUtils.byteCountToDisplaySize(finalUsedMemory - initialUsedMemory))); Resource targetResource = resourceSet.createResource(targetUri); Map<String, Object> saveOpts = new HashMap<String, Object>(); targetResource.save(saveOpts); LOG.log(Level.INFO, "Start moving elements"); targetResource.getContents().clear(); targetResource.getContents().addAll(sourceResource.getContents()); LOG.log(Level.INFO, "End moving elements"); LOG.log(Level.INFO, "Start saving"); targetResource.save(saveOpts); LOG.log(Level.INFO, "Saved"); if (targetResource instanceof KyanosHbaseResourceImpl) { KyanosHbaseResourceImpl.shutdownWithoutUnload((KyanosHbaseResourceImpl) targetResource); } else { targetResource.unload(); } } catch (ParseException e) { ATLMRUtils.showError(e.toString()); ATLMRUtils.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { ATLMRUtils.showError(e.toString()); e.printStackTrace(); } }
From source file:com.joey.Fujikom.generate.Generate.java
public static void main(String[] args) throws Exception { // ========== ?? ==================== // ??????// w w w .j a v a2 s.c o m // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className} // packageName ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4? String packageName = "com.joey.Fujikom.modules"; String moduleName = "factory"; // ???sys String subModuleName = ""; // ????? String className = "product"; // ??user String classAuthor = "ThinkGem"; // ThinkGem String functionName = "?"; // ?? // ??? //Boolean isEnable = false; Boolean isEnable = true; // ========== ?? ==================== if (!isEnable) { logger.error("????isEnable = true"); return; } if (StringUtils.isBlank(moduleName) || StringUtils.isBlank(moduleName) || StringUtils.isBlank(className) || StringUtils.isBlank(functionName)) { logger.error("??????????????"); return; } // ? String separator = File.separator; // ? File projectPath = new DefaultResourceLoader().getResource("").getFile(); while (!new File(projectPath.getPath() + separator + "src" + separator + "main").exists()) { projectPath = projectPath.getParentFile(); } logger.info("Project Path: {}", projectPath); // ? String tplPath = StringUtils.replace(projectPath + "/src/main/java/com/thinkgem/Fujikom/generate/template", "/", separator); logger.info("Template Path: {}", tplPath); // Java String javaPath = StringUtils.replaceEach( projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." }, new String[] { separator, separator }); logger.info("Java Path: {}", javaPath); // String viewPath = StringUtils.replace(projectPath + "/src/main/webapp/WEB-INF/views", "/", separator); logger.info("View Path: {}", viewPath); // ??? Configuration cfg = new Configuration(); cfg.setDefaultEncoding("UTF-8"); cfg.setDirectoryForTemplateLoading(new File(tplPath)); // ??? Map<String, String> model = Maps.newHashMap(); model.put("packageName", StringUtils.lowerCase(packageName)); model.put("moduleName", StringUtils.lowerCase(moduleName)); model.put("subModuleName", StringUtils.isNotBlank(subModuleName) ? "." + StringUtils.lowerCase(subModuleName) : ""); model.put("className", StringUtils.uncapitalize(className)); model.put("ClassName", StringUtils.capitalize(className)); model.put("classAuthor", StringUtils.isNotBlank(classAuthor) ? classAuthor : "Generate Tools"); model.put("classVersion", DateUtils.getDate()); model.put("functionName", functionName); model.put("tableName", model.get("moduleName") + (StringUtils.isNotBlank(subModuleName) ? "_" + StringUtils.lowerCase(subModuleName) : "") + "_" + model.get("className")); model.put("urlPrefix", model.get("moduleName") + (StringUtils.isNotBlank(subModuleName) ? "/" + StringUtils.lowerCase(subModuleName) : "") + "/" + model.get("className")); model.put("viewPrefix", //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+ model.get("urlPrefix")); model.put("permissionPrefix", model.get("moduleName") + (StringUtils.isNotBlank(subModuleName) ? ":" + StringUtils.lowerCase(subModuleName) : "") + ":" + model.get("className")); // ? Entity Template template = cfg.getTemplate("entity.ftl"); String content = FreeMarkers.renderTemplate(template, model); String filePath = javaPath + separator + model.get("moduleName") + separator + "entity" + separator + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + ".java"; writeFile(content, filePath); logger.info("Entity: {}", filePath); // ? Dao template = cfg.getTemplate("dao.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = javaPath + separator + model.get("moduleName") + separator + "dao" + separator + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + "Dao.java"; writeFile(content, filePath); logger.info("Dao: {}", filePath); // ? Service template = cfg.getTemplate("service.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = javaPath + separator + model.get("moduleName") + separator + "service" + separator + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + "Service.java"; writeFile(content, filePath); logger.info("Service: {}", filePath); // ? Controller template = cfg.getTemplate("controller.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = javaPath + separator + model.get("moduleName") + separator + "web" + separator + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + "Controller.java"; writeFile(content, filePath); logger.info("Controller: {}", filePath); // ? ViewForm template = cfg.getTemplate("viewForm.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = viewPath + separator + StringUtils.substringAfterLast(model.get("packageName"), ".") + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator + model.get("className") + "Form.jsp"; writeFile(content, filePath); logger.info("ViewForm: {}", filePath); // ? ViewList template = cfg.getTemplate("viewList.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = viewPath + separator + StringUtils.substringAfterLast(model.get("packageName"), ".") + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator + model.get("className") + "List.jsp"; writeFile(content, filePath); logger.info("ViewList: {}", filePath); logger.info("Generate Success."); }
From source file:edu.uchicago.mpcs53013.crime_topology.CrimeTopology.java
public static void main(String[] args) throws AlreadyAliveException, InvalidTopologyException { String zkIp = "hadoop-w-1.c.mpcs53013-2015.internal"; String zookeeperHost = zkIp + ":2181"; ZkHosts zkHosts = new ZkHosts(zookeeperHost); List<String> zkServers = new ArrayList<String>(); zkServers.add(zkIp);//from w w w . j av a2 s .co m SpoutConfig kafkaConfig = new SpoutConfig(zkHosts, "acidreflux-crime-events", "/acidreflux-crime-events", "test_id"); kafkaConfig.scheme = new SchemeAsMultiScheme(new StringScheme()); kafkaConfig.startOffsetTime = kafka.api.OffsetRequest.EarliestTime(); kafkaConfig.zkServers = zkServers; kafkaConfig.zkRoot = "/acidreflux-crime-events"; kafkaConfig.zkPort = 2181; kafkaConfig.forceFromStart = true; KafkaSpout kafkaSpout = new KafkaSpout(kafkaConfig); TopologyBuilder builder = new TopologyBuilder(); builder.setSpout("raw-crime-events", kafkaSpout, 1); builder.setBolt("filter-reports", new FilterReportsBolt(), 1).shuffleGrouping("raw-crime-events"); builder.setBolt("update-table", new UpdateCrimesBolt(), 1).fieldsGrouping("filter-reports", new Fields("ward")); Map conf = new HashMap(); conf.put(backtype.storm.Config.TOPOLOGY_WORKERS, 4); conf.put(backtype.storm.Config.TOPOLOGY_DEBUG, true); if (args != null && args.length > 0) { StormSubmitter.submitTopology(args[0], conf, builder.createTopology()); } else { LocalCluster cluster = new LocalCluster(); cluster.submitTopology("crime-topology", conf, builder.createTopology()); } }
From source file:Main.java
public static void main(final String[] args) { final List<String> asu = new ArrayList<String>(); asu.add("2"); asu.add("11"); asu.add("7"); asu.add("10"); asu.add("7"); asu.add("12"); asu.add("2"); asu.add("11"); asu.add("11"); asu.add("7"); asu.add("7"); asu.add("7"); List<String> list = new ArrayList<String>(); Map<String, Integer> counts = new HashMap<String, Integer>(); list.addAll(asu);//from ww w.jav a 2 s. c o m for (String item : list) { Integer count = counts.get(item); if (count == null) { count = 1; } else { count = count + 1; } counts.put(item, count); } Collections.sort(asu, new Comparator<String>() { @Override public int compare(final String left, final String right) { int result = counts.get(left).compareTo(counts.get(right)); if (result == 0) { result = left.compareTo(right); } return result; } }); System.out.println(asu); }
From source file:fr.inria.atlanmod.kyanos.benchmarks.KyanosMapCreator.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input file"); inputOpt.setArgs(1);/* w w w.java 2s . com*/ inputOpt.setRequired(true); Option outputOpt = OptionBuilder.create(OUT); outputOpt.setArgName("OUTPUT"); outputOpt.setDescription("Output directory"); outputOpt.setArgs(1); outputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); options.addOption(inputOpt); options.addOption(outputOpt); options.addOption(inClassOpt); CommandLineParser parser = new PosixParser(); try { PersistenceBackendFactoryRegistry.getFactories().put(NeoMapURI.NEO_MAP_SCHEME, new MapPersistenceBackendFactory()); CommandLine commandLine = parser.parse(options, args); URI sourceUri = URI.createFileURI(commandLine.getOptionValue(IN)); URI targetUri = NeoMapURI.createNeoMapURI(new File(commandLine.getOptionValue(OUT))); Class<?> inClazz = KyanosMapCreator.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("zxmi", new XMIResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put(NeoMapURI.NEO_MAP_SCHEME, PersistentResourceFactory.eINSTANCE); Resource sourceResource = resourceSet.createResource(sourceUri); Map<String, Object> loadOpts = new HashMap<String, Object>(); if ("zxmi".equals(sourceUri.fileExtension())) { loadOpts.put(XMIResource.OPTION_ZIP, Boolean.TRUE); } Runtime.getRuntime().gc(); long initialUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); LOG.log(Level.INFO, MessageFormat.format("Used memory before loading: {0}", MessageUtil.byteCountToDisplaySize(initialUsedMemory))); LOG.log(Level.INFO, "Loading source resource"); sourceResource.load(loadOpts); LOG.log(Level.INFO, "Source resource loaded"); Runtime.getRuntime().gc(); long finalUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); LOG.log(Level.INFO, MessageFormat.format("Used memory after loading: {0}", MessageUtil.byteCountToDisplaySize(finalUsedMemory))); LOG.log(Level.INFO, MessageFormat.format("Memory use increase: {0}", MessageUtil.byteCountToDisplaySize(finalUsedMemory - initialUsedMemory))); Resource targetResource = resourceSet.createResource(targetUri); Map<String, Object> saveOpts = new HashMap<String, Object>(); List<StoreOption> storeOptions = new ArrayList<StoreOption>(); storeOptions.add(MapResourceOptions.EStoreMapOption.AUTOCOMMIT); saveOpts.put(MapResourceOptions.STORE_OPTIONS, storeOptions); targetResource.save(saveOpts); LOG.log(Level.INFO, "Start moving elements"); targetResource.getContents().clear(); targetResource.getContents().addAll(sourceResource.getContents()); LOG.log(Level.INFO, "End moving elements"); LOG.log(Level.INFO, "Start saving"); targetResource.save(saveOpts); LOG.log(Level.INFO, "Saved"); if (targetResource instanceof PersistentResourceImpl) { PersistentResourceImpl.shutdownWithoutUnload((PersistentResourceImpl) targetResource); } else { targetResource.unload(); } } catch (ParseException e) { MessageUtil.showError(e.toString()); MessageUtil.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { MessageUtil.showError(e.toString()); e.printStackTrace(); } }
From source file:com.github.benyzhous.springboot.web.core.gateway.sign.backend.Sign.java
/** * Demo/*from w w w. j a va2 s . c om*/ * * @param args * @throws Exception */ public static void main(String[] args) throws Exception { String uri = "/list"; String httpMethod = "GET"; Map<String, String> headers = new HashMap<String, String>(); headers.put("x-ca-proxy-signature", "YTaCd7ZCm6wRYY/mc2Dj4lQOviuR4oSJA9YGxjYHYIo="); headers.put("x-ca-proxy-signature-headers", "RequestId,X-Ca-Proxy-Signature-Secret-Key"); headers.put("x-ca-proxy-signature-secret-key", "kaishu2099"); headers.put("requestid", "1609A1D2-2845-488E-B052-9BA2143D51B5"); //headers.put("HeaderKey2", "HeaderValue2"); Map<String, Object> paramsMap = new HashMap<String, Object>(); paramsMap.put("appid", "wxbb22392b3fefd76f"); paramsMap.put("AppID", "4206209"); /**paramsMap.put("FormKey1", "FormValue1"); paramsMap.put("FormKey2", "FormValue2");*/ byte[] inputStreamBytes = new byte[] {}; String gatewaySign = headers.get("x-ca-proxy-signature"); System.out.println("API??:" + gatewaySign); String serviceSign = serviceSign(uri, httpMethod, headers, paramsMap, inputStreamBytes); System.out.println("???:" + serviceSign); System.out.println("????:" + gatewaySign.equals(serviceSign)); }
From source file:com.ibm.ecod.watson.AlchemyDataNewsTest.java
public static void main(String[] args) { AlchemyDataNews service = new AlchemyDataNews(); service.setApiKey("5fc91e98eacfa5ebf83440e8c6a61d0f60fa380b"); Map<String, Object> params = new HashMap<String, Object>(); String[] fields = new String[] { "enriched.url.title", "enriched.url.url", "enriched.url.author", "enriched.url.publicationDate", "enriched.url.enrichedTitle.entities", "enriched.url.enrichedTitle.docSentiment" }; params.put(AlchemyDataNews.RETURN, StringUtils.join(fields, ",")); params.put(AlchemyDataNews.START, "now-60d"); params.put(AlchemyDataNews.END, "now"); //params.put(AlchemyDataNews.COUNT, 7); //Query on adjacent nested fields: params.put("q.enriched.url.enrichedTitle.entities.entity", "|text=IBM,type=company|"); params.put("q.enriched.url.enrichedTitle.docSentiment.type", "positive"); params.put("q.enriched.url.enrichedTitle.taxonomy.taxonomy_.label", "technology and computing"); DocumentsResult result = service.getNewsDocuments(params); System.out.println(result);// ww w. j a v a2 s .c o m }
From source file:com.ibm.watson.developer_cloud.alchemy_data_news.v1.GetNewsDocumentExample.java
public static void main(String[] args) { AlchemyDataNews service = new AlchemyDataNews(); service.setApiKey("<api_key>"); Map<String, Object> params = new HashMap<String, Object>(); String[] fields = new String[] { "enriched.url.title", "enriched.url.url", "enriched.url.author", "enriched.url.publicationDate", "enriched.url.enrichedTitle.entities", "enriched.url.enrichedTitle.docSentiment" }; params.put(AlchemyDataNews.RETURN, StringUtils.join(fields, ",")); params.put(AlchemyDataNews.START, "1440720000"); params.put(AlchemyDataNews.END, "1441407600"); params.put(AlchemyDataNews.COUNT, 7); //Query on adjacent nested fields: params.put("q.enriched.url.enrichedTitle.entities.entity", "|text=IBM,type=company|"); params.put("q.enriched.url.enrichedTitle.docSentiment.type", "positive"); params.put("q.enriched.url.enrichedTitle.taxonomy.taxonomy_.label", "technology and computing"); DocumentsResult result = service.getNewsDocuments(params).execute(); System.out.println(result);//from www . j av a 2s .c o m }
From source file:org.eclipseplugins.impexeditor.http.ImpexHttpClient.java
public static void main(final String[] args) throws Exception { final ImpexHttpClient impexHttpClient = new ImpexHttpClient("http://localhost:9001/hac"); final long startTime = System.currentTimeMillis(); final Map<String, JsonArray> allatypes = new HashMap<String, JsonArray>(); for (final JsonValue type : impexHttpClient.getAllTypes()) { allatypes.put(type.asString(), impexHttpClient.getTypeandAttribute(type.asString()).get("attributes").asArray()); }/* w w w . j ava 2s. c om*/ for (final String type : allatypes.keySet()) { System.out.println("type :" + type); for (final JsonValue string : allatypes.get(type)) { System.out.println("---- " + string.asString()); } } final long stopTime = System.currentTimeMillis(); final long elapsedTime = stopTime - startTime; System.out.println("Success elapsed time in seconde " + TimeUnit.MILLISECONDS.toSeconds(elapsedTime)); }
From source file:com.bt.aloha.batchtest.PerformanceMeasurmentDao.java
public static void main(String[] args) throws Exception { BasicConfigurator.configure();/*from ww w . j av a 2 s. co m*/ ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( "batchTestApplicationContext.xml"); PerformanceMeasurmentDao dao = (PerformanceMeasurmentDao) applicationContext .getBean("performanceMeasurementDaoBean"); if (dao != null) { List<Metrics> metrics = dao.findMetricsByRunId(2192); Map<Long, List<Metrics>> m = new HashMap<Long, List<Metrics>>(); m.put(2192L, metrics); Chart c = new Chart(m); m = dao.findLastXMetricsForTestType(10, "performance.database"); c = new Chart(m); c.saveCombinedChart(new File("unitPerSecond-historical.jpg"), "Runs Per Second", "threads", "runs per second", "Standard Deviation", "threads", "std. deviation"); } // List<Long> runids = dao.findLastXRunId(1000, "unknown"); // for(long runid : runids) // { // List<Long[]> vals = dao.getNumberOfApplicationThreadsFromDescription(runid); // int sz = vals.size(); // Long[] v = new Long[sz]; // int p = 0; // for(Long[] i : vals) // v[p++] = i[1]; // long min = v[0]; // long max = v[sz-1]; // long inc = 0; // if(sz>1) // inc = (max - min) / (sz - 1); // for(Long[] i : vals) // { // String format = String.format(Metrics.TI_STRING, i[1], min, max, inc); // dao.updateThreadInfo(i[0], format); // } // // } System.exit(0); }