List of usage examples for com.google.common.collect Maps newHashMap
public static <K, V> HashMap<K, V> newHashMap()
From source file:org.apache.shindig.gadgets.oauth.OAuthCommandLine.java
public static void main(String[] argv) throws Exception { Map<String, String> params = Maps.newHashMap(); for (int i = 0; i < argv.length; i += 2) { params.put(argv[i], argv[i + 1]); }/*from ww w .j a va2s . c om*/ final String httpProxy = params.get("--httpProxy"); final String consumerKey = params.get("--consumerKey"); final String consumerSecret = params.get("--consumerSecret"); final String xOauthRequestor = params.get("--requestorId"); final String accessToken = params.get("--accessToken"); final String tokenSecret = params.get("--tokenSecret"); final String method = params.get("--method") == null ? "GET" : params.get("--method"); String url = params.get("--url"); String contentType = params.get("--contentType"); String postBody = params.get("--postBody"); String postFile = params.get("--postFile"); String paramLocation = params.get("--paramLocation"); String bodySigning = params.get("--bodySigning"); HttpRequest request = new HttpRequest(Uri.parse(url)); if (contentType != null) { request.setHeader("Content-Type", contentType); } else { request.setHeader("Content-Type", OAuth.FORM_ENCODED); } if (postBody != null) { request.setPostBody(postBody.getBytes()); } if (postFile != null) { request.setPostBody(IOUtils.toByteArray(new FileInputStream(postFile))); } OAuthParamLocation paramLocationEnum = OAuthParamLocation.URI_QUERY; if (paramLocation != null) { paramLocationEnum = OAuthParamLocation.valueOf(paramLocation); } BodySigning bodySigningEnum = BodySigning.none; if (bodySigning != null) { bodySigningEnum = BodySigning.valueOf(bodySigning); } List<OAuth.Parameter> oauthParams = Lists.newArrayList(); UriBuilder target = new UriBuilder(Uri.parse(url)); String query = target.getQuery(); target.setQuery(null); oauthParams.addAll(OAuth.decodeForm(query)); if (OAuth.isFormEncoded(contentType) && request.getPostBodyAsString() != null) { oauthParams.addAll(OAuth.decodeForm(request.getPostBodyAsString())); } else if (bodySigningEnum == BodySigning.legacy) { oauthParams.add(new OAuth.Parameter(request.getPostBodyAsString(), "")); } else if (bodySigningEnum == BodySigning.hash) { oauthParams.add(new OAuth.Parameter(OAuthConstants.OAUTH_BODY_HASH, new String( Base64.encodeBase64(DigestUtils.sha(request.getPostBodyAsString().getBytes())), "UTF-8"))); } if (consumerKey != null) { oauthParams.add(new OAuth.Parameter(OAuth.OAUTH_CONSUMER_KEY, consumerKey)); } if (xOauthRequestor != null) { oauthParams.add(new OAuth.Parameter("xoauth_requestor_id", xOauthRequestor)); } OAuthConsumer consumer = new OAuthConsumer(null, consumerKey, consumerSecret, null); OAuthAccessor accessor = new OAuthAccessor(consumer); accessor.accessToken = accessToken; accessor.tokenSecret = tokenSecret; OAuthMessage message = accessor.newRequestMessage(method, target.toString(), oauthParams); List<Map.Entry<String, String>> entryList = OAuthRequest.selectOAuthParams(message); switch (paramLocationEnum) { case AUTH_HEADER: request.addHeader("Authorization", OAuthRequest.getAuthorizationHeader(entryList)); break; case POST_BODY: if (!OAuth.isFormEncoded(contentType)) { throw new RuntimeException("OAuth param location can only be post_body if post body if of " + "type x-www-form-urlencoded"); } String oauthData = OAuthUtil.formEncode(message.getParameters()); request.setPostBody(CharsetUtil.getUtf8Bytes(oauthData)); break; case URI_QUERY: request.setUri(Uri.parse(OAuthUtil.addParameters(request.getUri().toString(), entryList))); break; } request.setMethod(method); HttpFetcher fetcher = new BasicHttpFetcher(httpProxy); HttpResponse response = fetcher.fetch(request); System.out.println("Request ------------------------------"); System.out.println(request.toString()); System.out.println("Response -----------------------------"); System.out.println(response.toString()); }
From source file:pt.uminho.anote2.carrot.linkage.examples.MoreConfigurationsOfOneAlgorithmInCachingController.java
@SuppressWarnings({ "unchecked" }) public static void main(String[] args) { /*//ww w . ja v a 2 s . c om * Create a controller that caches all documents. */ final Controller controller = ControllerFactory.createCachingPooling(IDocumentSource.class); /* * You can define global values for some attributes. These will apply to all * configurations we will define below, unless the specific configuration * overrides the global attributes. */ final Map<String, Object> globalAttributes = new HashMap<String, Object>(); LingoClusteringAlgorithmDescriptor.attributeBuilder(globalAttributes).preprocessingPipeline() .documentAssigner().exactPhraseAssignment(false); /* * Now we will define two different configurations of the Lingo algorithm. One * will be optimized for speed of clustering, while the other will optimize the * quality of clusters. */ final Map<String, Object> fastAttributes = Maps.newHashMap(); LingoClusteringAlgorithmDescriptor.attributeBuilder(fastAttributes).desiredClusterCountBase(20) .matrixReducer().factorizationQuality(FactorizationQuality.LOW); LingoClusteringAlgorithmDescriptor.attributeBuilder(fastAttributes).preprocessingPipeline().caseNormalizer() .dfThreshold(2); final Map<String, Object> accurateAttributes = Maps.newHashMap(); LingoClusteringAlgorithmDescriptor.attributeBuilder(accurateAttributes).desiredClusterCountBase(40) .matrixReducer().factorizationQuality(FactorizationQuality.HIGH); LingoClusteringAlgorithmDescriptor.attributeBuilder(accurateAttributes).preprocessingPipeline() .documentAssigner().exactPhraseAssignment(true); LingoClusteringAlgorithmDescriptor.attributeBuilder(fastAttributes).preprocessingPipeline().caseNormalizer() .dfThreshold(1); /* * We initialize the controller passing the global attributes and the two * configurations. Notice that a configuration consists of the component * class (can be a document source as well as a clustering algorithm), its * string identifier and attributes. */ controller.init(globalAttributes, new ProcessingComponentConfiguration(LingoClusteringAlgorithm.class, "lingo-fast", fastAttributes), new ProcessingComponentConfiguration(LingoClusteringAlgorithm.class, "lingo-accurate", accurateAttributes)); /* * Now we can call the two different clustering configurations. Notice that * because we now use string identifiers instead of classes, we pass the document * source class name rather than the class itself. */ final Map<String, Object> attributes = new HashMap<String, Object>(); CommonAttributesDescriptor.attributeBuilder(attributes).query("data mining"); final ProcessingResult fastResult = controller.process(attributes, Bing3WebDocumentSource.class.getName(), "lingo-fast"); ConsoleFormatter.displayClusters(fastResult.getClusters()); final ProcessingResult accurateResult = controller.process(attributes, Bing3WebDocumentSource.class.getName(), "lingo-accurate"); ConsoleFormatter.displayClusters(accurateResult.getClusters()); }
From source file:com.anhth12.test.Main.java
public static void main(String[] args) { SparkConf conf = new SparkConf(); conf.setMaster("spark://192.168.56.101:7077"); conf.setAppName("TEST"); conf.setIfMissing("spark.executor.instance", Integer.toString(1)); conf.setIfMissing("spark.executor.core", Integer.toString(1)); conf.setIfMissing("spark.executor.memory", "512m"); conf.setIfMissing("spark.driver.memory", "512m"); String blockIntervalString = Long.toString(1000l); conf.setIfMissing("spark.streaming.blockInterval", blockIntervalString); conf.setIfMissing("spark.streaming.gracefulStopTimeout", blockIntervalString); conf.setIfMissing("spark.clean.ttl", Integer.toString(20 * 3000)); conf.setIfMissing("spark.logConf", "true"); conf.setIfMissing("spark.ui.port", Integer.toString(4040)); try {//www . ja v a 2 s . com conf.setJars(new String[] { Main.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath() }); } catch (Exception e) { throw new IllegalStateException(e); } JavaStreamingContext streamingContext = new JavaStreamingContext(new JavaSparkContext(conf), new Duration(100)); Map<String, String> kafkaParams = new HashMap<>(); kafkaParams.put("zookeeper.connect", "192.168.56.101:2181"); kafkaParams.put("group.id", "LAMBDA-BATCHLAYER-" + System.currentTimeMillis()); kafkaParams.put("serializer.encoding", "UTF-8"); // kafkaParams.put(null, null) Map<String, Integer> topicMap = Maps.newHashMap(); topicMap.put("LambdaInput", 1); JavaPairDStream<String, String> dstream = KafkaUtils.createStream(streamingContext, "192.168.56.101:2181", "GROUP", topicMap); // JavaPairDStream<String, String> dstream = KafkaUtils.createStream(streamingContext, // String.class, // String.class, // StringDecoder.class, // StringDecoder.class, // kafkaParams, topicMap, // StorageLevel.MEMORY_AND_DISK_2()); JavaDStream<String> lines = dstream.map(new Function<Tuple2<String, String>, String>() { @Override public String call(Tuple2<String, String> tuple2) { System.out.println("message: " + tuple2._2()); return tuple2._2(); } }); JavaDStream<String> words = lines.flatMap(new FlatMapFunction<String, String>() { @Override public Iterable<String> call(String x) { System.out.println("x: " + x); return Lists.newArrayList(x.split(",")); } }); JavaPairDStream<String, Integer> wordCounts = words.mapToPair(new PairFunction<String, String, Integer>() { @Override public Tuple2<String, Integer> call(String s) { return new Tuple2<String, Integer>(s, 1); } }).reduceByKey(new Function2<Integer, Integer, Integer>() { @Override public Integer call(Integer i1, Integer i2) { return i1 + i2; } }); wordCounts.print(); streamingContext.start(); streamingContext.awaitTermination(); }
From source file:org.sakaiproject.nakamura.lite.soak.derby.CreateUsersAndGroupsSoak.java
public static void main(String[] argv) throws ClientPoolException, StorageClientException, AccessDeniedException, ClassNotFoundException, IOException { int totalUsers = 1000; int nthreads = 10; if (argv.length > 0) { nthreads = StorageClientUtils.getSetting(Integer.valueOf(argv[0]), nthreads); }/*from w w w . j av a2 s . co m*/ if (argv.length > 1) { totalUsers = StorageClientUtils.getSetting(Integer.valueOf(argv[1]), totalUsers); } ConfigurationImpl configuration = new ConfigurationImpl(); Map<String, Object> properties = Maps.newHashMap(); properties.put("keyspace", "n"); properties.put("acl-column-family", "ac"); properties.put("authorizable-column-family", "au"); properties.put("content-column-family", "cn"); configuration.activate(properties); CreateUsersAndGroupsSoak createUsersAndGroupsSoak = new CreateUsersAndGroupsSoak(totalUsers, DerbySetup.getClientPool(configuration, "jdbc:derby:target/soak/db;create=true"), configuration); createUsersAndGroupsSoak.launchSoak(nthreads); }
From source file:org.sakaiproject.nakamura.lite.soak.mysql.CreateUsersAndGroupsSoak.java
public static void main(String[] argv) throws ClientPoolException, StorageClientException, AccessDeniedException, ClassNotFoundException, IOException { int totalUsers = 1000; int nthreads = 10; if (argv.length > 0) { nthreads = StorageClientUtils.getSetting(Integer.valueOf(argv[0]), nthreads); }//from ww w .j a va 2 s .c o m if (argv.length > 1) { totalUsers = StorageClientUtils.getSetting(Integer.valueOf(argv[1]), totalUsers); } ConfigurationImpl configuration = new ConfigurationImpl(); Map<String, Object> properties = Maps.newHashMap(); properties.put("keyspace", "n"); properties.put("acl-column-family", "ac"); properties.put("authorizable-column-family", "au"); properties.put("content-column-family", "cn"); configuration.activate(properties); CreateUsersAndGroupsSoak createUsersAndGroupsSoak = new CreateUsersAndGroupsSoak(totalUsers, MysqlSetup.getClientPool(configuration), configuration); createUsersAndGroupsSoak.launchSoak(nthreads); }
From source file:org.lisapark.octopus.util.gss.GssListUtils.java
public static void main(String[] args) { String newEntry = "RECNUM=3,A1=900,B1=0.02"; String formulas = "MODEL1=A1 + B1*RECNUM"; Map<String, String> entryMap = Maps.newHashMap(); entryMap.put("A1", "800"); entryMap.put("B1", "0.02"); GssListUtils gssList = new GssListUtils("test", "demoForecast_USFutures15", "Forecast", "demo@lisa-park.com", "isasdemo"); try {// ww w .j a v a2s.c o m ListFeed listFeed = gssList.loadSheet(); if (listFeed.getEntries().isEmpty()) { ListEntry entry = gssList.addNewEntryValues(newEntry); if (formulas != null && !formulas.isEmpty()) { gssList.updateEntryFormulas(entry, newEntry, formulas); } gssList.getService().insert(gssList.getListFeedUrl(), entry); } else { ListEntry entry = gssList.updateEntryValues(listFeed.getEntries().get(0), newEntry); if (formulas != null && !formulas.isEmpty()) { gssList.updateEntryFormulas(entry, newEntry, formulas); } entry.update(); // gssList.getService().update(gssList.getListFeedUrl(), entry); } } catch (ServiceException ex) { Exceptions.printStackTrace(ex); } catch (IOException ex) { Exceptions.printStackTrace(ex); } }
From source file:org.sakaiproject.nakamura.lite.soak.mongo.CreateUsersAndGroupsSoak.java
public static void main(String[] argv) throws ClientPoolException, StorageClientException, AccessDeniedException, ClassNotFoundException, IOException { int totalUsers = 1000; int nthreads = 10; if (argv.length > 0) { nthreads = StorageClientUtils.getSetting(Integer.valueOf(argv[0]), nthreads); }/*w ww. ja v a 2s .c om*/ if (argv.length > 1) { totalUsers = StorageClientUtils.getSetting(Integer.valueOf(argv[1]), totalUsers); } ConfigurationImpl configuration = new ConfigurationImpl(); Map<String, Object> properties = Maps.newHashMap(); properties.put("keyspace", "n"); properties.put("acl-column-family", "ac"); properties.put("authorizable-column-family", "au"); properties.put("content-column-family", "cn"); configuration.activate(properties); CreateUsersAndGroupsSoak createUsersAndGroupsSoak = new CreateUsersAndGroupsSoak(totalUsers, getClientPool(configuration), configuration); createUsersAndGroupsSoak.launchSoak(nthreads); }
From source file:org.sakaiproject.nakamura.lite.soak.mysql.ContentCreateSoak.java
public static void main(String[] argv) throws ClientPoolException, StorageClientException, AccessDeniedException, ClassNotFoundException, IOException { int totalContent = 100000; int nthreads = 1; if (argv.length > 0) { nthreads = StorageClientUtils.getSetting(Integer.valueOf(argv[0]), nthreads); }/*from w ww .j a v a 2s.c o m*/ if (argv.length > 1) { totalContent = StorageClientUtils.getSetting(Integer.valueOf(argv[1]), totalContent); } ConfigurationImpl configuration = new ConfigurationImpl(); Map<String, Object> cm = Maps.newHashMap(); cm.put("sling:resourceType", "test/resourcetype"); cm.put("sakai:pooled-content-manager", new String[] { "a", "b" }); cm.put("sakai:type", "sdfsdaggdsfgsdgsd"); cm.put("sakai:marker", "marker-marker-marker"); Map<String, Object> properties = Maps.newHashMap(); properties.put("keyspace", "n"); properties.put("acl-column-family", "ac"); properties.put("authorizable-column-family", "au"); properties.put("content-column-family", "cn"); configuration.activate(properties); ContentCreateSoak contentCreateSoak = new ContentCreateSoak(totalContent, MysqlSetup.getClientPool(configuration), configuration, cm); contentCreateSoak.launchSoak(nthreads); }
From source file:org.dllearner.algorithms.qtl.experiments.Diagrams.java
public static void main(String[] args) throws Exception { File dir = new File(args[0]); dir.mkdirs();// ww w .j a v a 2 s. c o m Properties config = new Properties(); config.load(Thread.currentThread().getContextClassLoader() .getResourceAsStream("org/dllearner/algorithms/qtl/qtl-eval-config.properties")); String url = config.getProperty("url"); String username = config.getProperty("username"); String password = config.getProperty("password"); Class.forName("com.mysql.jdbc.Driver").newInstance(); // url = "jdbc:mysql://address=(protocol=tcp)(host=[2001:638:902:2010:0:168:35:138])(port=3306)(user=root)/qtl"; Connection conn = DriverManager.getConnection(url, username, password); int[] nrOfExamplesIntervals = { 5, 10, // 15, 20, // 25, 30 }; double[] noiseIntervals = { 0.0, 0.1, 0.2, 0.3, // 0.4, // 0.6 }; Map<HeuristicType, String> measure2ColumnName = Maps.newHashMap(); measure2ColumnName.put(HeuristicType.FMEASURE, "avg_fscore_best_returned"); measure2ColumnName.put(HeuristicType.PRED_ACC, "avg_predacc_best_returned"); measure2ColumnName.put(HeuristicType.MATTHEWS_CORRELATION, "avg_mathcorr_best_returned"); HeuristicType[] measures = { HeuristicType.PRED_ACC, HeuristicType.FMEASURE, HeuristicType.MATTHEWS_CORRELATION }; String[] labels = { "A_1", "F_1", "MCC" }; // get distinct noise intervals // |E| vs fscore String sql = "SELECT nrOfExamples,%s from eval_overall WHERE heuristic_measure = ? && noise = ? ORDER BY nrOfExamples"; PreparedStatement ps; for (double noise : noiseIntervals) { String s = ""; s += "\t"; s += Joiner.on("\t").join(Ints.asList(nrOfExamplesIntervals)); s += "\n"; for (HeuristicType measure : measures) { ps = conn.prepareStatement(String.format(sql, measure2ColumnName.get(measure))); ps.setString(1, measure.toString()); ps.setDouble(2, noise); ResultSet rs = ps.executeQuery(); s += measure; while (rs.next()) { int nrOfExamples = rs.getInt(1); double avgFscore = rs.getDouble(2); s += "\t" + avgFscore; } s += "\n"; } Files.write(s, new File(dir, "examplesVsScore-" + noise + ".tsv"), Charsets.UTF_8); } // noise vs fscore sql = "SELECT noise,%s from eval_overall WHERE heuristic_measure = ? && nrOfExamples = ?"; NavigableMap<Integer, Map<HeuristicType, double[][]>> input = new TreeMap<>(); for (int nrOfExamples : nrOfExamplesIntervals) { String s = ""; s += "\t"; s += Joiner.on("\t").join(Doubles.asList(noiseIntervals)); s += "\n"; String gnuplot = ""; // F-score ps = conn.prepareStatement( "SELECT noise,avg_fscore_best_returned from eval_overall WHERE heuristic_measure = 'FMEASURE' && nrOfExamples = ?"); ps.setInt(1, nrOfExamples); ResultSet rs = ps.executeQuery(); gnuplot += "\"F_1\"\n"; while (rs.next()) { double noise = rs.getDouble(1); double avgFscore = rs.getDouble(2); gnuplot += noise + "," + avgFscore + "\n"; } // precision gnuplot += "\n\n"; ps = conn.prepareStatement( "SELECT noise,avg_precision_best_returned from eval_overall WHERE heuristic_measure = 'FMEASURE' && nrOfExamples = ?"); ps.setInt(1, nrOfExamples); rs = ps.executeQuery(); gnuplot += "\"precision\"\n"; while (rs.next()) { double noise = rs.getDouble(1); double avgFscore = rs.getDouble(2); gnuplot += noise + "," + avgFscore + "\n"; } // recall gnuplot += "\n\n"; ps = conn.prepareStatement( "SELECT noise,avg_recall_best_returned from eval_overall WHERE heuristic_measure = 'FMEASURE' && nrOfExamples = ?"); ps.setInt(1, nrOfExamples); rs = ps.executeQuery(); gnuplot += "\"recall\"\n"; while (rs.next()) { double noise = rs.getDouble(1); double avgFscore = rs.getDouble(2); gnuplot += noise + "," + avgFscore + "\n"; } // MCC gnuplot += "\n\n"; ps = conn.prepareStatement( "SELECT noise,avg_mathcorr_best_returned from eval_overall WHERE heuristic_measure = 'MATTHEWS_CORRELATION' && nrOfExamples = ?"); ps.setInt(1, nrOfExamples); rs = ps.executeQuery(); gnuplot += "\"MCC\"\n"; while (rs.next()) { double noise = rs.getDouble(1); double avgFscore = rs.getDouble(2); gnuplot += noise + "," + avgFscore + "\n"; } // baseline F-score gnuplot += "\n\n"; ps = conn.prepareStatement( "SELECT noise,avg_fscore_baseline from eval_overall WHERE heuristic_measure = 'FMEASURE' && nrOfExamples = ?"); ps.setInt(1, nrOfExamples); rs = ps.executeQuery(); gnuplot += "\"baseline F_1\"\n"; while (rs.next()) { double noise = rs.getDouble(1); double avgFscore = rs.getDouble(2); gnuplot += noise + "," + avgFscore + "\n"; } // baseline MCC gnuplot += "\n\n"; ps = conn.prepareStatement( "SELECT noise,avg_mathcorr_baseline from eval_overall WHERE heuristic_measure = 'MATTHEWS_CORRELATION' && nrOfExamples = ?"); ps.setInt(1, nrOfExamples); rs = ps.executeQuery(); gnuplot += "\"baseline MCC\"\n"; while (rs.next()) { double noise = rs.getDouble(1); double avgFscore = rs.getDouble(2); gnuplot += noise + "," + avgFscore + "\n"; } Files.write(gnuplot.trim(), new File(dir, "noiseVsScore-" + nrOfExamples + ".dat"), Charsets.UTF_8); } if (!input.isEmpty()) { // plotNoiseVsFscore(input); } }
From source file:org.sakaiproject.nakamura.lite.soak.memory.CreateUsersAndGroupsSoak.java
public static void main(String[] argv) throws ClientPoolException, StorageClientException, AccessDeniedException, ClassNotFoundException, IOException { int totalUsers = 1000; int nthreads = 10; if (argv.length > 0) { nthreads = StorageClientUtils.getSetting(Integer.valueOf(argv[0]), nthreads); }/* w w w. j a v a 2s. c o m*/ if (argv.length > 1) { totalUsers = StorageClientUtils.getSetting(Integer.valueOf(argv[1]), totalUsers); } ConfigurationImpl configuration = new ConfigurationImpl(); Map<String, Object> properties = Maps.newHashMap(); properties.put("keyspace", "n"); properties.put("acl-column-family", "ac"); properties.put("authorizable-column-family", "au"); properties.put("content-column-family", "cn"); configuration.activate(properties); CreateUsersAndGroupsSoak createUsersAndGroupsSoak = new CreateUsersAndGroupsSoak(totalUsers, getConnectionPool(configuration), configuration); createUsersAndGroupsSoak.launchSoak(nthreads); }