List of usage examples for java.util Map get
V get(Object key);
From source file:com.alibaba.jstorm.hdfs.transaction.RocksDbHdfsState.java
public static void main(String[] args) { Map conf = new HashMap<Object, Object>(); conf.putAll(Utils.loadConf(args[0])); RocksDbHdfsState<String, Integer> state = new RocksDbHdfsState<String, Integer>(); state.setStateName(String.valueOf(1)); // setup checkpoint int batchNum = JStormUtils.parseInt(conf.get("batch.num"), 100); state.initEnv("test", conf, "/tmp/rocksdb_test"); String remoteCpPath = null;/*from w ww.j a va2 s .c o m*/ for (int i = 0; i < batchNum; i++) { state.put(String.valueOf(i % 20), i); state.checkpoint(i); remoteCpPath = state.backup(i); state.remove(i); } state.cleanup(); state.initEnv("test", conf, "/tmp/rocksdb_test"); state.restore(remoteCpPath); for (int i = 0; i < 20; i++) { Integer value = state.get(String.valueOf(i)); LOG.info("key={}, value={}", String.valueOf(i), value); } state.cleanup(); }
From source file:org.apache.s4.adapter.Adapter.java
public static void main(String args[]) { Options options = new Options(); options.addOption(OptionBuilder.withArgName("corehome").hasArg().withDescription("core home").create("c")); options.addOption(/* w ww.j av a 2 s . c om*/ OptionBuilder.withArgName("instanceid").hasArg().withDescription("instance id").create("i")); options.addOption( OptionBuilder.withArgName("configtype").hasArg().withDescription("configuration type").create("t")); options.addOption(OptionBuilder.withArgName("userconfig").hasArg() .withDescription("user-defined legacy data adapter configuration file").create("d")); CommandLineParser parser = new GnuParser(); CommandLine commandLine = null; try { commandLine = parser.parse(options, args); } catch (ParseException pe) { System.err.println(pe.getLocalizedMessage()); System.exit(1); } int instanceId = -1; if (commandLine.hasOption("i")) { String instanceIdStr = commandLine.getOptionValue("i"); try { instanceId = Integer.parseInt(instanceIdStr); } catch (NumberFormatException nfe) { System.err.println("Bad instance id: %s" + instanceIdStr); System.exit(1); } } if (commandLine.hasOption("c")) { coreHome = commandLine.getOptionValue("c"); } String configType = "typical"; if (commandLine.hasOption("t")) { configType = commandLine.getOptionValue("t"); } String userConfigFilename = null; if (commandLine.hasOption("d")) { userConfigFilename = commandLine.getOptionValue("d"); } File userConfigFile = new File(userConfigFilename); if (!userConfigFile.isFile()) { System.err.println("Bad user configuration file: " + userConfigFilename); System.exit(1); } File coreHomeFile = new File(coreHome); if (!coreHomeFile.isDirectory()) { System.err.println("Bad core home: " + coreHome); System.exit(1); } if (instanceId > -1) { System.setProperty("instanceId", "" + instanceId); } else { System.setProperty("instanceId", "" + S4Util.getPID()); } String configBase = coreHome + File.separatorChar + "conf" + File.separatorChar + configType; String configPath = configBase + File.separatorChar + "adapter-conf.xml"; File configFile = new File(configPath); if (!configFile.exists()) { System.err.printf("adapter config file %s does not exist\n", configPath); System.exit(1); } // load adapter config xml ApplicationContext coreContext; coreContext = new FileSystemXmlApplicationContext("file:" + configPath); ApplicationContext context = coreContext; Adapter adapter = (Adapter) context.getBean("adapter"); ApplicationContext appContext = new FileSystemXmlApplicationContext( new String[] { "file:" + userConfigFilename }, context); Map listenerBeanMap = appContext.getBeansOfType(EventProducer.class); if (listenerBeanMap.size() == 0) { System.err.println("No user-defined listener beans"); System.exit(1); } EventProducer[] eventListeners = new EventProducer[listenerBeanMap.size()]; int index = 0; for (Iterator it = listenerBeanMap.keySet().iterator(); it.hasNext(); index++) { String beanName = (String) it.next(); System.out.println("Adding producer " + beanName); eventListeners[index] = (EventProducer) listenerBeanMap.get(beanName); } adapter.setEventListeners(eventListeners); }
From source file:TreeMapExample.java
public static void main(String[] args) { Map<Integer, String> map = new TreeMap<Integer, String>(); // Add Items to the TreeMap map.put(new Integer(1), "One"); map.put(new Integer(2), "Two"); map.put(new Integer(3), "Three"); map.put(new Integer(4), "Four"); map.put(new Integer(5), "Five"); map.put(new Integer(6), "Six"); map.put(new Integer(7), "Seven"); map.put(new Integer(8), "Eight"); map.put(new Integer(9), "Nine"); map.put(new Integer(10), "Ten"); // Use iterator to display the keys and associated values System.out.println("Map Values Before: "); Set keys = map.keySet();/*from w ww . j a v a 2 s . com*/ for (Iterator i = keys.iterator(); i.hasNext();) { Integer key = (Integer) i.next(); String value = (String) map.get(key); System.out.println(key + " = " + value); } // Remove the entry with key 6 System.out.println("\nRemove element with key 6"); map.remove(new Integer(6)); // Use iterator to display the keys and associated values System.out.println("\nMap Values After: "); keys = map.keySet(); for (Iterator i = keys.iterator(); i.hasNext();) { Integer key = (Integer) i.next(); String value = (String) map.get(key); System.out.println(key + " = " + value); } }
From source file:io.rodeo.chute.ChuteMain.java
public static void main(String[] args) throws SQLException, JsonParseException, JsonMappingException, IOException { InputStream is = new FileInputStream(new File(CONFIG_FILENAME)); ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE); ChuteConfiguration config = mapper.readValue(is, ChuteConfiguration.class); Map<String, Importer> importManagers = new HashMap<String, Importer>(config.importerConfigurations.size()); for (Entry<String, ImporterConfiguration> importerConfig : config.importerConfigurations.entrySet()) { importManagers.put(importerConfig.getKey(), importerConfig.getValue().createImporter()); }/*from w ww .j a va2 s .co m*/ Map<String, Exporter> exportManagers = new HashMap<String, Exporter>(config.exporterConfigurations.size()); for (Entry<String, ExporterConfiguration> exporterConfig : config.exporterConfigurations.entrySet()) { exportManagers.put(exporterConfig.getKey(), exporterConfig.getValue().createExporter()); } for (Entry<String, ConnectionConfiguration> connectionConfig : config.connectionConfigurations.entrySet()) { importManagers.get(connectionConfig.getValue().in) .addProcessor(exportManagers.get(connectionConfig.getValue().out)); } for (Entry<String, Exporter> exportManager : exportManagers.entrySet()) { exportManager.getValue().start(); } for (Entry<String, Importer> importManager : importManagers.entrySet()) { importManager.getValue().start(); } }
From source file:de.mycrobase.jcloudapp.Main.java
public static void main(String[] args) throws Exception { try {/* w w w . j a v a 2 s. co m*/ // borrowed from https://github.com/cmur2/gloudapp ImageNormal = ImageIO.read(Main.class.getResourceAsStream("gloudapp.png")); ImageWorking = ImageIO.read(Main.class.getResourceAsStream("gloudapp_working.png")); IconNormal = new ImageIcon(ImageNormal.getScaledInstance(64, 64, Image.SCALE_SMOOTH)); IconLarge = new ImageIcon(ImageNormal); } catch (IOException ex) { showErrorDialog("Could not load images!\n" + ex); System.exit(1); } URI serviceUrl = URI.create("http://my.cl.ly:80/"); File storage = getStorageFile(); if (storage.exists() && storage.isFile()) { Yaml yaml = new Yaml(); try { Map<String, String> m = (Map<String, String>) yaml.load(new FileInputStream(storage)); // avoid NPE by implicitly assuming the presence of a service URL if (m.containsKey("service_url")) { serviceUrl = URI.create(m.get("service_url")); } } catch (IOException ex) { showErrorDialog("Loading settings from .cloudapp-cli failed: " + ex); System.exit(1); } } Main app = new Main(serviceUrl); app.login(args); app.run(); }
From source file:edu.cmu.lti.oaqa.knn4qa.apps.ExtractDataAndQueryAsSparseVectors.java
public static void main(String[] args) { String optKeys[] = { CommonParams.MAX_NUM_QUERY_PARAM, MAX_NUM_DATA_PARAM, CommonParams.MEMINDEX_PARAM, IN_QUERIES_PARAM, OUT_QUERIES_PARAM, OUT_DATA_PARAM, TEXT_FIELD_PARAM, TEST_QTY_PARAM, }; String optDescs[] = { CommonParams.MAX_NUM_QUERY_DESC, MAX_NUM_DATA_DESC, CommonParams.MEMINDEX_DESC, IN_QUERIES_DESC, OUT_QUERIES_DESC, OUT_DATA_DESC, TEXT_FIELD_DESC, TEST_QTY_DESC }; boolean hasArg[] = { true, true, true, true, true, true, true, true }; ParamHelper prmHlp = null;/*from w w w. ja va 2s .c om*/ try { prmHlp = new ParamHelper(args, optKeys, optDescs, hasArg); CommandLine cmd = prmHlp.getCommandLine(); Options opt = prmHlp.getOptions(); int maxNumQuery = Integer.MAX_VALUE; String tmpn = cmd.getOptionValue(CommonParams.MAX_NUM_QUERY_PARAM); if (tmpn != null) { try { maxNumQuery = Integer.parseInt(tmpn); } catch (NumberFormatException e) { UsageSpecify(CommonParams.MAX_NUM_QUERY_PARAM, opt); } } int maxNumData = Integer.MAX_VALUE; tmpn = cmd.getOptionValue(MAX_NUM_DATA_PARAM); if (tmpn != null) { try { maxNumData = Integer.parseInt(tmpn); } catch (NumberFormatException e) { UsageSpecify(MAX_NUM_DATA_PARAM, opt); } } String memIndexPref = cmd.getOptionValue(CommonParams.MEMINDEX_PARAM); if (null == memIndexPref) { UsageSpecify(CommonParams.MEMINDEX_PARAM, opt); } String textField = cmd.getOptionValue(TEXT_FIELD_PARAM); if (null == textField) { UsageSpecify(TEXT_FIELD_PARAM, opt); } textField = textField.toLowerCase(); int fieldId = -1; for (int i = 0; i < FeatureExtractor.mFieldNames.length; ++i) if (FeatureExtractor.mFieldNames[i].compareToIgnoreCase(textField) == 0) { fieldId = i; break; } if (-1 == fieldId) { Usage("Wrong field index, should be one of the following: " + String.join(",", FeatureExtractor.mFieldNames), opt); } InMemForwardIndex indx = new InMemForwardIndex( FeatureExtractor.indexFileName(memIndexPref, FeatureExtractor.mFieldNames[fieldId])); BM25SimilarityLucene bm25simil = new BM25SimilarityLucene(FeatureExtractor.BM25_K1, FeatureExtractor.BM25_B, indx); String inQueryFile = cmd.getOptionValue(IN_QUERIES_PARAM); String outQueryFile = cmd.getOptionValue(OUT_QUERIES_PARAM); if ((inQueryFile == null) != (outQueryFile == null)) { Usage("You should either specify both " + IN_QUERIES_PARAM + " and " + OUT_QUERIES_PARAM + " or none of them", opt); } String outDataFile = cmd.getOptionValue(OUT_DATA_PARAM); tmpn = cmd.getOptionValue(TEST_QTY_PARAM); int testQty = 0; if (tmpn != null) { try { testQty = Integer.parseInt(tmpn); } catch (NumberFormatException e) { UsageSpecify(TEST_QTY_PARAM, opt); } } ArrayList<DocEntry> testDocEntries = new ArrayList<DocEntry>(); ArrayList<DocEntry> testQueryEntries = new ArrayList<DocEntry>(); ArrayList<TrulySparseVector> testDocVectors = new ArrayList<TrulySparseVector>(); ArrayList<TrulySparseVector> testQueryVectors = new ArrayList<TrulySparseVector>(); if (outDataFile != null) { BufferedWriter out = new BufferedWriter( new OutputStreamWriter(CompressUtils.createOutputStream(outDataFile))); ArrayList<DocEntryExt> docEntries = indx.getDocEntries(); for (int id = 0; id < Math.min(maxNumData, docEntries.size()); ++id) { DocEntry e = docEntries.get(id).mDocEntry; TrulySparseVector v = bm25simil.getDocSparseVector(e, false); if (id < testQty) { testDocEntries.add(e); testDocVectors.add(v); } outputVector(out, v); } out.close(); } Splitter splitOnSpace = Splitter.on(' ').trimResults().omitEmptyStrings(); if (outQueryFile != null) { BufferedReader inpText = new BufferedReader( new InputStreamReader(CompressUtils.createInputStream(inQueryFile))); BufferedWriter out = new BufferedWriter( new OutputStreamWriter(CompressUtils.createOutputStream(outQueryFile))); String queryText = XmlHelper.readNextXMLIndexEntry(inpText); for (int queryQty = 0; queryText != null && queryQty < maxNumQuery; queryText = XmlHelper .readNextXMLIndexEntry(inpText), queryQty++) { Map<String, String> queryFields = null; // 1. Parse a query try { queryFields = XmlHelper.parseXMLIndexEntry(queryText); } catch (Exception e) { System.err.println("Parsing error, offending QUERY:\n" + queryText); throw new Exception("Parsing error."); } String fieldText = queryFields.get(FeatureExtractor.mFieldsSOLR[fieldId]); if (fieldText == null) { fieldText = ""; } ArrayList<String> tmpa = new ArrayList<String>(); for (String s : splitOnSpace.split(fieldText)) tmpa.add(s); DocEntry e = indx.createDocEntry(tmpa.toArray(new String[tmpa.size()])); TrulySparseVector v = bm25simil.getDocSparseVector(e, true); if (queryQty < testQty) { testQueryEntries.add(e); testQueryVectors.add(v); } outputVector(out, v); } out.close(); } int testedQty = 0, diffQty = 0; // Now let's do some testing for (int iq = 0; iq < testQueryEntries.size(); ++iq) { DocEntry queryEntry = testQueryEntries.get(iq); TrulySparseVector queryVector = testQueryVectors.get(iq); for (int id = 0; id < testDocEntries.size(); ++id) { DocEntry docEntry = testDocEntries.get(id); TrulySparseVector docVector = testDocVectors.get(id); float val1 = bm25simil.compute(queryEntry, docEntry); float val2 = TrulySparseVector.scalarProduct(queryVector, docVector); ++testedQty; if (Math.abs(val1 - val2) > 1e5) { System.err.println( String.format("Potential mismatch BM25=%f <-> scalar product=%f", val1, val2)); ++diffQty; } } } if (testedQty > 0) System.out.println(String.format("Tested %d Mismatched %d", testedQty, diffQty)); } catch (ParseException e) { Usage("Cannot parse arguments: " + e, prmHlp != null ? prmHlp.getOptions() : null); e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); System.err.println("Terminating due to an exception: " + e); System.exit(1); } }
From source file:com.msopentech.odatajclient.engine.performance.PerfTestReporter.java
public static void main(final String[] args) throws Exception { // 1. check input directory final File reportdir = new File(args[0] + File.separator + "target" + File.separator + "surefire-reports"); if (!reportdir.isDirectory()) { throw new IllegalArgumentException("Expected directory, got " + args[0]); }/*from ww w .j a va 2 s. co m*/ // 2. read test data from surefire output final File[] xmlReports = reportdir.listFiles(new FilenameFilter() { @Override public boolean accept(final File dir, final String name) { return name.endsWith("-output.txt"); } }); final Map<String, Map<String, Double>> testData = new TreeMap<String, Map<String, Double>>(); for (File xmlReport : xmlReports) { final BufferedReader reportReader = new BufferedReader(new FileReader(xmlReport)); try { while (reportReader.ready()) { String line = reportReader.readLine(); final String[] parts = line.substring(0, line.indexOf(':')).split("\\."); final String testClass = parts[0]; if (!testData.containsKey(testClass)) { testData.put(testClass, new TreeMap<String, Double>()); } line = reportReader.readLine(); testData.get(testClass).put(parts[1], Double.valueOf(line.substring(line.indexOf(':') + 2, line.indexOf('[')))); } } finally { IOUtils.closeQuietly(reportReader); } } // 3. build XSLX output (from template) final HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(args[0] + File.separator + "src" + File.separator + "test" + File.separator + "resources" + File.separator + XLS)); for (Map.Entry<String, Map<String, Double>> entry : testData.entrySet()) { final Sheet sheet = workbook.getSheet(entry.getKey()); int rows = 0; for (Map.Entry<String, Double> subentry : entry.getValue().entrySet()) { final Row row = sheet.createRow(rows++); Cell cell = row.createCell(0); cell.setCellValue(subentry.getKey()); cell = row.createCell(1); cell.setCellValue(subentry.getValue()); } } final FileOutputStream out = new FileOutputStream( args[0] + File.separator + "target" + File.separator + XLS); try { workbook.write(out); } finally { IOUtils.closeQuietly(out); } }
From source file:cn.dehui.zbj1984105.GetAccountHierarchy.java
public static void main(String[] args) { try {//from www. j a v a2 s .c om // Log SOAP XML request and response. AdWordsServiceLogger.log(); // Get AdWordsUser from "~/adwords.properties". AdWordsUser user = new AdWordsUser("adwords.properties").generateClientAdWordsUser(null); // Get the ServicedAccountService. ManagedCustomerServiceInterface managedCustomerService = user .getService(AdWordsService.V201209.MANAGED_CUSTOMER_SERVICE); // Create selector. Selector selector = new Selector(); selector.setFields(new String[] { "Login", "CustomerId" }); // Get results. ManagedCustomerPage page = managedCustomerService.get(selector); if (page.getEntries() != null) { // Create map from customerId to customer node. Map<Long, ManagedCustomerTreeNode> customerIdToCustomerNode = new HashMap<Long, ManagedCustomerTreeNode>(); // Create account tree nodes for each customer. for (ManagedCustomer customer : page.getEntries()) { ManagedCustomerTreeNode node = new ManagedCustomerTreeNode(); node.managedCustomer = customer; customerIdToCustomerNode.put(customer.getCustomerId(), node); } // For each link, connect nodes in tree. if (page.getLinks() != null) { for (ManagedCustomerLink link : page.getLinks()) { ManagedCustomerTreeNode managerNode = customerIdToCustomerNode .get(link.getManagerCustomerId()); ManagedCustomerTreeNode childNode = customerIdToCustomerNode .get(link.getClientCustomerId()); childNode.parentNode = managerNode; if (managerNode != null) { managerNode.childAccounts.add(childNode); } } } // Find the root account node in the tree. ManagedCustomerTreeNode rootNode = null; for (ManagedCustomer account : page.getEntries()) { if (customerIdToCustomerNode.get(account.getCustomerId()).parentNode == null) { rootNode = customerIdToCustomerNode.get(account.getCustomerId()); break; } } // Display account tree. System.out.println("Login, CustomerId (Status)"); System.out.println(rootNode.toTreeString(0, new StringBuffer())); } else { System.out.println("No serviced accounts were found."); } } catch (Exception e) { e.printStackTrace(); } }
From source file:io.parallec.sample.app.http.HttpDiffRequestsSameServerApp.java
public static void main(String[] args) { ParallelClient pc = new ParallelClient(); Map<String, Object> responseContext = new HashMap<String, Object>(); responseContext.put("temp", null); pc.prepareHttpGet("/userdata/sample_weather_$ZIP.txt") .setReplaceVarMapToSingleTargetSingleVar("ZIP", Arrays.asList("95037", "48824"), "www.parallec.io") .setResponseContext(responseContext).execute(new ParallecResponseHandler() { public void onCompleted(ResponseOnSingleTask res, Map<String, Object> responseContext) { String temp = new FilterRegex("(.*)").filter(res.getResponseContent()); System.out.println("\n!!Temperature: " + temp + " TargetHost: " + res.getHost()); responseContext.put("temp", temp); }// ww w . ja v a 2s . com }); int tempGlobal = Integer.parseInt((String) responseContext.get("temp")); Asserts.check(tempGlobal <= 100 && tempGlobal >= 0, " Fail to extract output from sample weather API. Fail different request to same server test"); pc.releaseExternalResources(); }
From source file:kindleclippings.quizlet.QuizletSync.java
public static void main(String[] args) throws IOException, JSONException, URISyntaxException, InterruptedException, BackingStoreException { ProgressMonitor progress = new ProgressMonitor(null, "QuizletSync", "loading Kindle clippings file", 0, 100);// w ww . ja v a2 s . c o m progress.setMillisToPopup(0); progress.setMillisToDecideToPopup(0); progress.setProgress(0); try { Map<String, List<Clipping>> books = readClippingsFile(); if (books == null) return; if (books.isEmpty()) { JOptionPane.showMessageDialog(null, "no clippings to be uploaded", "QuizletSync", JOptionPane.OK_OPTION); return; } progress.setNote("checking Quizlet account"); progress.setProgress(5); Preferences prefs = getPrefs(); QuizletAPI api = new QuizletAPI(prefs.get("access_token", null)); Collection<TermSet> sets = null; try { progress.setNote("checking Quizlet library"); progress.setProgress(10); sets = api.getSets(prefs.get("user_id", null)); } catch (IOException e) { if (e.toString().contains("401")) { // Not Authorized => Token has been revoked clearPrefs(); prefs = getPrefs(); api = new QuizletAPI(prefs.get("access_token", null)); sets = api.getSets(prefs.get("user_id", null)); } else { throw e; } } progress.setProgress(15); progress.setMaximum(15 + books.size()); progress.setNote("uploading new notes"); Map<String, TermSet> indexedSets = new HashMap<String, TermSet>(sets.size()); for (TermSet t : sets) { indexedSets.put(t.getTitle(), t); } int pro = 15; int createdSets = 0; int createdTerms = 0; int updatedTerms = 0; for (List<Clipping> c : books.values()) { String book = c.get(0).getBook(); progress.setNote(book); progress.setProgress(pro++); TermSet termSet = indexedSets.get(book); if (termSet == null) { if (c.size() < 2) { System.err.println("ignored [" + book + "] (need at least two notes)"); continue; } addSet(api, book, c); createdSets++; createdTerms += c.size(); continue; } // compare against existing terms for (Clipping cl : c) { if (!checkExistingTerm(cl, termSet)) { addTerm(api, termSet, cl); updatedTerms++; } } } progress.setProgress(pro++); if (createdSets == 0 && updatedTerms == 0) { JOptionPane.showMessageDialog(null, "Done.\nNo new data was uploaded", "QuizletSync", JOptionPane.OK_OPTION); } else if (createdSets > 0) { JOptionPane.showMessageDialog(null, String.format( "Done.\nCreated %d new sets with %d cards, and added %d cards to existing sets", createdSets, createdTerms, updatedTerms), "QuizletSync", JOptionPane.OK_OPTION); } else { JOptionPane.showMessageDialog(null, String.format("Done.\nAdded %d cards to existing sets", updatedTerms), "QuizletSync", JOptionPane.OK_OPTION); } } finally { progress.close(); } System.exit(0); }