List of usage examples for com.google.common.collect ArrayListMultimap create
public static <K, V> ArrayListMultimap<K, V> create()
From source file:com.netflix.genie.client.sample.CommandServiceSampleClient.java
/** * Main for running client code.//from w w w . j a v a2s. com * * @param args program arguments * @throws Exception on issue. */ public static void main(final String[] args) throws Exception { // Initialize Eureka, if it is being used // LOG.info("Initializing Eureka"); // ApplicationServiceClient.initEureka("test"); LOG.info("Initializing list of Genie servers"); ConfigurationManager.getConfigInstance().setProperty("genie2Client.ribbon.listOfServers", "localhost:7001"); LOG.info("Initializing ApplicationServiceClient"); final ApplicationServiceClient appClient = ApplicationServiceClient.getInstance(); final Application app1 = appClient.createApplication( ApplicationServiceSampleClient.getSampleApplication(ApplicationServiceSampleClient.ID)); LOG.info("Created application:"); LOG.info(app1.toString()); final Application app2 = appClient.createApplication( ApplicationServiceSampleClient.getSampleApplication(ApplicationServiceSampleClient.ID + "2")); LOG.info("Created application:"); LOG.info(app2.toString()); LOG.info("Initializing CommandServiceClient"); final CommandServiceClient commandClient = CommandServiceClient.getInstance(); LOG.info("Creating command pig13_mr2"); final Command command1 = commandClient.createCommand(createSampleCommand(ID)); commandClient.setApplicationForCommand(command1.getId(), app1); LOG.info("Created command:"); LOG.info(command1.toString()); LOG.info("Getting Commands using specified filter criteria name = " + CMD_NAME); final Multimap<String, String> params = ArrayListMultimap.create(); params.put("name", CMD_NAME); final List<Command> commands = commandClient.getCommands(params); if (commands.isEmpty()) { LOG.info("No commands found for specified criteria."); } else { LOG.info("Commands found:"); for (final Command command : commands) { LOG.info(command.toString()); } } LOG.info("Getting command config by id"); final Command command3 = commandClient.getCommand(ID); LOG.info(command3.toString()); LOG.info("Updating existing command config"); command3.setStatus(CommandStatus.INACTIVE); final Command command4 = commandClient.updateCommand(ID, command3); LOG.info(command4.toString()); LOG.info("Configurations for command with id " + command1.getId()); final Set<String> configs = commandClient.getConfigsForCommand(command1.getId()); for (final String config : configs) { LOG.info("Config = " + config); } LOG.info("Adding configurations to command with id " + command1.getId()); final Set<String> newConfigs = new HashSet<>(); newConfigs.add("someNewConfigFile"); newConfigs.add("someOtherNewConfigFile"); final Set<String> configs2 = commandClient.addConfigsToCommand(command1.getId(), newConfigs); for (final String config : configs2) { LOG.info("Config = " + config); } LOG.info("Updating set of configuration files associated with id " + command1.getId()); //This should remove the original config leaving only the two in this set final Set<String> configs3 = commandClient.updateConfigsForCommand(command1.getId(), newConfigs); for (final String config : configs3) { LOG.info("Config = " + config); } LOG.info("Deleting all the configuration files from the command with id " + command1.getId()); //This should remove the original config leaving only the two in this set final Set<String> configs4 = commandClient.removeAllConfigsForCommand(command1.getId()); for (final String config : configs4) { //Shouldn't print anything LOG.info("Config = " + config); } /**************** Begin tests for tag Api's *********************/ LOG.info("Get tags for command with id " + command1.getId()); final Set<String> tags = command1.getTags(); for (final String tag : tags) { LOG.info("Tag = " + tag); } LOG.info("Adding tags to command with id " + command1.getId()); final Set<String> newTags = new HashSet<>(); newTags.add("tag1"); newTags.add("tag2"); final Set<String> tags2 = commandClient.addTagsToCommand(command1.getId(), newTags); for (final String tag : tags2) { LOG.info("Tag = " + tag); } LOG.info("Updating set of tags associated with id " + command1.getId()); //This should remove the original config leaving only the two in this set final Set<String> tags3 = commandClient.updateTagsForCommand(command1.getId(), newTags); for (final String tag : tags3) { LOG.info("Tag = " + tag); } LOG.info("Deleting one tag from the command with id " + command1.getId()); //This should remove the "tag3" from the tags final Set<String> tags5 = commandClient.removeTagForCommand(command1.getId(), "tag1"); for (final String tag : tags5) { //Shouldn't print anything LOG.info("Tag = " + tag); } LOG.info("Deleting all the tags from the command with id " + command1.getId()); //This should remove the original config leaving only the two in this set final Set<String> tags4 = commandClient.removeAllConfigsForCommand(command1.getId()); for (final String tag : tags4) { //Shouldn't print anything LOG.info("Config = " + tag); } /********************** End tests for tag Api's **********************/ LOG.info("Application for command with id " + command1.getId()); final Application application = commandClient.getApplicationForCommand(command1.getId()); LOG.info("Application = " + application); LOG.info("Removing Application for command with id " + command1.getId()); final Application application2 = commandClient.removeApplicationForCommand(command1.getId()); LOG.info("Application = " + application2); LOG.info("Getting all the clusters for command with id " + command1.getId()); final Set<Cluster> clusters = commandClient.getClustersForCommand(command1.getId()); for (final Cluster cluster : clusters) { LOG.info("Cluster = " + cluster); } LOG.info("Deleting command config using id"); final Command command5 = commandClient.deleteCommand(ID); LOG.info("Deleted command config with id: " + ID); LOG.info(command5.toString()); LOG.info("Deleting all applications"); final List<Application> deletedApps = appClient.deleteAllApplications(); LOG.info("Deleted all applications"); LOG.info(deletedApps.toString()); LOG.info("Done"); }
From source file:com.netflix.genie.client.sample.ClusterServiceSampleClient.java
/** * Main for running client code./*from w w w .ja va 2s. c o m*/ * * @param args program arguments * @throws Exception On issue. */ public static void main(final String[] args) throws Exception { // Initialize Eureka, if it is being used // LOG.info("Initializing Eureka"); // ClusterServiceClient.initEureka("test"); LOG.info("Initializing list of Genie servers"); ConfigurationManager.getConfigInstance().setProperty("genie2Client.ribbon.listOfServers", "localhost:7001"); LOG.info("Initializing ApplicationServiceClient"); final ApplicationServiceClient appClient = ApplicationServiceClient.getInstance(); final Application app1 = appClient.createApplication( ApplicationServiceSampleClient.getSampleApplication(ApplicationServiceSampleClient.ID)); LOG.info("Created application:"); LOG.info(app1.toString()); final Application app2 = appClient.createApplication( ApplicationServiceSampleClient.getSampleApplication(ApplicationServiceSampleClient.ID + "2")); LOG.info("Created application:"); LOG.info(app2.toString()); LOG.info("Initializing CommandServiceClient"); final CommandServiceClient commandClient = CommandServiceClient.getInstance(); LOG.info("Creating command pig13_mr2"); final Command command1 = commandClient .createCommand(CommandServiceSampleClient.createSampleCommand(CommandServiceSampleClient.ID)); commandClient.setApplicationForCommand(command1.getId(), app1); LOG.info("Created command:"); LOG.info(command1.toString()); final List<Command> commands = new ArrayList<>(); commands.add(command1); LOG.info("Initializing ClusterConfigServiceClient"); final ClusterServiceClient clusterClient = ClusterServiceClient.getInstance(); LOG.info("Creating new cluster configuration"); final Cluster cluster1 = clusterClient.createCluster(createSampleCluster(ID)); clusterClient.addCommandsToCluster(cluster1.getId(), commands); LOG.info("Cluster config created with id: " + cluster1.getId()); LOG.info(cluster1.toString()); LOG.info("Getting cluster config by id"); final Cluster cluster2 = clusterClient.getCluster(cluster1.getId()); LOG.info(cluster2.toString()); LOG.info("Getting clusterConfigs using specified filter criteria"); final Multimap<String, String> params = ArrayListMultimap.create(); params.put("name", NAME); params.put("adHoc", "false"); params.put("test", "true"); params.put("limit", "3"); final List<Cluster> clusters = clusterClient.getClusters(params); if (clusters != null && !clusters.isEmpty()) { for (final Cluster cluster : clusters) { LOG.info(cluster.toString()); } } else { LOG.info("No clusters found for parameters"); } LOG.info("Configurations for cluster with id " + cluster1.getId()); final Set<String> configs = clusterClient.getConfigsForCluster(cluster1.getId()); for (final String config : configs) { LOG.info("Config = " + config); } LOG.info("Adding configurations to cluster with id " + cluster1.getId()); final Set<String> newConfigs = new HashSet<>(); newConfigs.add("someNewConfigFile"); newConfigs.add("someOtherNewConfigFile"); final Set<String> configs2 = clusterClient.addConfigsToCluster(cluster1.getId(), newConfigs); for (final String config : configs2) { LOG.info("Config = " + config); } LOG.info("Updating set of configuration files associated with id " + cluster1.getId()); //This should remove the original config leaving only the two in this set final Set<String> configs3 = clusterClient.updateConfigsForCluster(cluster1.getId(), newConfigs); for (final String config : configs3) { LOG.info("Config = " + config); } /**************** Begin tests for tag Api's *********************/ LOG.info("Get tags for cluster with id " + cluster1.getId()); final Set<String> tags = cluster1.getTags(); for (final String tag : tags) { LOG.info("Tag = " + tag); } LOG.info("Adding tags to cluster with id " + cluster1.getId()); final Set<String> newTags = new HashSet<>(); newTags.add("tag1"); newTags.add("tag2"); final Set<String> tags2 = clusterClient.addTagsToCluster(cluster1.getId(), newTags); for (final String tag : tags2) { LOG.info("Tag = " + tag); } LOG.info("Updating set of tags associated with id " + cluster1.getId()); //This should remove the original config leaving only the two in this set final Set<String> tags3 = clusterClient.updateTagsForCluster(cluster1.getId(), newTags); for (final String tag : tags3) { LOG.info("Tag = " + tag); } LOG.info("Deleting one tag from the cluster with id " + cluster1.getId()); //This should remove the "tag3" from the tags final Set<String> tags5 = clusterClient.removeTagForCluster(cluster1.getId(), "tag1"); for (final String tag : tags5) { //Shouldn't print anything LOG.info("Tag = " + tag); } LOG.info("Deleting all the tags from the cluster with id " + cluster1.getId()); //This should remove the original config leaving only the two in this set final Set<String> tags4 = clusterClient.removeAllTagsForCluster(cluster1.getId()); for (final String tag : tags4) { //Shouldn't print anything LOG.info("Config = " + tag); } /********************** End tests for tag Api's **********************/ LOG.info("Commands for cluster with id " + cluster1.getId()); final List<Command> commands1 = clusterClient.getCommandsForCluster(cluster1.getId()); for (final Command command : commands1) { LOG.info("Command = " + command); } LOG.info("Adding commands to cluster with id " + cluster1.getId()); final List<Command> newCmds = new ArrayList<>(); newCmds.add(commandClient.createCommand(CommandServiceSampleClient.createSampleCommand(ID + "something"))); newCmds.add(commandClient.createCommand(CommandServiceSampleClient.createSampleCommand(null))); final List<Command> commands2 = clusterClient.addCommandsToCluster(cluster1.getId(), newCmds); for (final Command command : commands2) { LOG.info("Command = " + command); } LOG.info("Updating set of commands files associated with id " + cluster1.getId()); //This should remove the original config leaving only the two in this set final List<Command> commands3 = clusterClient.updateCommandsForCluster(cluster1.getId(), newCmds); for (final Command command : commands3) { LOG.info("Command = " + command); } LOG.info("Deleting the command from the cluster with id " + ID + "something"); final Set<Command> commands4 = clusterClient.removeCommandForCluster(cluster1.getId(), ID + "something"); for (final Command command : commands4) { LOG.info("Command = " + command); } LOG.info("Deleting all the commands from the command with id " + command1.getId()); final List<Command> commands5 = clusterClient.removeAllCommandsForCluster(cluster1.getId()); for (final Command command : commands5) { //Shouldn't print anything LOG.info("Command = " + command); } LOG.info("Updating existing cluster config"); cluster2.setStatus(ClusterStatus.TERMINATED); final Cluster cluster3 = clusterClient.updateCluster(cluster2.getId(), cluster2); LOG.info("Cluster updated:"); LOG.info(cluster3.toString()); LOG.info("Deleting cluster config using id"); final Cluster cluster4 = clusterClient.deleteCluster(cluster1.getId()); LOG.info("Deleted cluster config with id: " + cluster1.getId()); LOG.info(cluster4.toString()); LOG.info("Deleting command config using id"); final Command command5 = commandClient.deleteCommand(command1.getId()); LOG.info("Deleted command config with id: " + command1.getId()); LOG.info(command5.toString()); LOG.info("Deleting commands in newCmd"); for (final Command cmd : newCmds) { commandClient.deleteCommand(cmd.getId()); } LOG.info("Deleting application config using id"); final Application app3 = appClient.deleteApplication(app1.getId()); LOG.info("Deleted application config with id: " + app1.getId()); LOG.info(app3.toString()); LOG.info("Deleting application config using id"); final Application app4 = appClient.deleteApplication(app2.getId()); LOG.info("Deleted application config with id: " + app2.getId()); LOG.info(app4.toString()); LOG.info("Done"); }
From source file:com.google.devtools.build.android.RClassGeneratorAction.java
public static void main(String[] args) throws Exception { final Stopwatch timer = Stopwatch.createStarted(); OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class); if (args.length == 1 && args[0].startsWith("@")) { args = Files.readAllLines(Paths.get(args[0].substring(1)), StandardCharsets.UTF_8) .toArray(new String[0]); }// w ww .j av a2s . c o m optionsParser.parseAndExitUponError(args); Options options = optionsParser.getOptions(Options.class); Preconditions.checkNotNull(options.classJarOutput); final AndroidResourceProcessor resourceProcessor = new AndroidResourceProcessor(STD_LOGGER); try (ScopedTemporaryDirectory scopedTmp = new ScopedTemporaryDirectory("android_res_compile_tmp")) { Path tmp = scopedTmp.getPath(); Path classOutPath = tmp.resolve("compiled_classes"); LOGGER.fine(String.format("Setup finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS))); List<SymbolFileProvider> libraries = new ArrayList<>(); for (DependencySymbolFileProvider library : options.libraries) { libraries.add(library); } // Note that we need to write the R class for the main binary (so proceed even if there // are no libraries). if (options.primaryRTxt != null) { String appPackageName = options.packageForR; if (appPackageName == null) { appPackageName = VariantConfiguration.getManifestPackage(options.primaryManifest.toFile()); } Multimap<String, SymbolLoader> libSymbolMap = ArrayListMultimap.create(); SymbolLoader fullSymbolValues = resourceProcessor.loadResourceSymbolTable(libraries, appPackageName, options.primaryRTxt, libSymbolMap); LOGGER.fine(String.format("Load symbols finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS))); // For now, assuming not used for libraries and setting final access for fields. if (fullSymbolValues != null) { resourceProcessor.writePackageRClasses(libSymbolMap, fullSymbolValues, appPackageName, classOutPath, true /* finalFields */); LOGGER.fine(String.format("Finished R.class at %sms", timer.elapsed(TimeUnit.MILLISECONDS))); } } else { Files.createDirectories(classOutPath); } // We write .class files to temp, then jar them up after (we create a dummy jar, even if // there are no class files). resourceProcessor.createClassJar(classOutPath, options.classJarOutput); LOGGER.fine(String.format("createClassJar finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS))); } finally { resourceProcessor.shutdown(); } LOGGER.fine(String.format("Compile action done in %sms", timer.elapsed(TimeUnit.MILLISECONDS))); }
From source file:org.apache.ctakes.temporal.data.analysis.CompareFeatureStructures.java
public static void main(String[] args) throws Exception { Options options = CliFactory.parseArguments(Options.class, args); List<Class<?>> annotationClasses = Lists.newArrayList(); for (String annotationClassName : options.getAnnotationClassNames()) { annotationClasses.add(Class.forName(annotationClassName)); }/* ww w . jav a 2 s .c o m*/ MyersDiff<String> stringDiff = new MyersDiff<String>(); MyersDiff<FeatureStructure> fsDiff = new MyersDiff<FeatureStructure>(new FeatureStructureEqualizer()); File originalDir = options.getDirectory1(); File revisedDir = options.getDirectory2(); Patch<String> dirPatch = stringDiff.diff(originalDir.list(), revisedDir.list()); if (!dirPatch.getDeltas().isEmpty()) { log("--- %s files\n", originalDir); log("+++ %s files\n", revisedDir); log(dirPatch); } else { for (String fileName : originalDir.list()) { File originalFile = new File(originalDir, fileName); File revisedFile = new File(revisedDir, fileName); JCas originalJCas = readXMI(originalFile); JCas revisedJCas = readXMI(revisedFile); List<String> originalViews = getViewNames(originalJCas); List<String> revisedViews = getViewNames(revisedJCas); Patch<String> viewsPatch = stringDiff.diff(originalViews, revisedViews); if (!viewsPatch.getDeltas().isEmpty()) { log("--- %s views\n", originalFile); log("+++ %s views\n", revisedFile); log(viewsPatch); } else { for (String viewName : originalViews) { JCas originalView = originalJCas.getView(viewName); JCas revisedView = revisedJCas.getView(viewName); List<FeatureStructure> originalFSes = toFeatureStructures(originalView, annotationClasses); List<FeatureStructure> revisedFSes = toFeatureStructures(revisedView, annotationClasses); Patch<FeatureStructure> fsPatch = fsDiff.diff(originalFSes, revisedFSes); if (!fsPatch.getDeltas().isEmpty()) { log("--- %s view %s\n", originalFile, viewName); log("+++ %s view %s\n", revisedFile, viewName); for (Delta<FeatureStructure> fsDelta : fsPatch.getDeltas()) { logHeader(fsDelta); switch (fsDelta.getType()) { case DELETE: case INSERT: log(fsDelta); break; case CHANGE: List<String> originalLines = toLines(fsDelta.getOriginal().getLines()); List<String> revisedLines = toLines(fsDelta.getRevised().getLines()); Patch<String> linesPatch = stringDiff.diff(originalLines, revisedLines); ListMultimap<Integer, String> deletes = ArrayListMultimap.create(); ListMultimap<Integer, String> inserts = ArrayListMultimap.create(); Set<Integer> skips = Sets.newHashSet(); for (Delta<String> linesDelta : linesPatch.getDeltas()) { Chunk<String> originalChunk = linesDelta.getOriginal(); Chunk<String> revisedChunk = linesDelta.getRevised(); int start = originalChunk.getPosition(); deletes.putAll(start, originalChunk.getLines()); inserts.putAll(start, revisedChunk.getLines()); for (int i = start; i < start + originalChunk.size(); ++i) { skips.add(i); } } for (int i = 0; i < originalLines.size(); ++i) { if (!skips.contains(i)) { log(" %s\n", originalLines.get(i)); } for (String line : deletes.get(i)) { log("-%s\n", line); } for (String line : inserts.get(i)) { log("+%s\n", line); } } break; } } } } } } } }
From source file:it.units.malelab.ege.MappingPropertiesExperimenter.java
public static void main(String[] args) throws IOException, InterruptedException, ExecutionException { final int n = 10000; final int nDist = 10000; //prepare problems and methods List<String> problems = Lists.newArrayList("bool-parity5", "bool-mopm3", "sr-keijzer6", "sr-nguyen7", "sr-pagie1", "sr-vladislavleva4", "other-klandscapes3", "other-klandscapes7", "other-text"); List<String> mappers = new ArrayList<>(); for (int gs : new int[] { 64, 128, 256, 512, 1024 }) { mappers.add("ge-" + gs + "-2"); mappers.add("ge-" + gs + "-4"); mappers.add("ge-" + gs + "-8"); mappers.add("ge-" + gs + "-12"); mappers.add("pige-" + gs + "-4"); mappers.add("pige-" + gs + "-8"); mappers.add("pige-" + gs + "-16"); mappers.add("pige-" + gs + "-24"); mappers.add("hge-" + gs + "-0"); mappers.add("whge-" + gs + "-2"); mappers.add("whge-" + gs + "-3"); mappers.add("whge-" + gs + "-5"); }// ww w. ja v a2 s. co m mappers.add("sge-0-5"); mappers.add("sge-0-6"); mappers.add("sge-0-7"); mappers.add("sge-0-8"); mappers.clear(); mappers.addAll(Lists.newArrayList("ge-1024-8", "pige-1024-16", "hge-1024-0", "whge-1024-3", "sge-0-6")); PrintStream filePrintStream = null; if (args.length > 0) { filePrintStream = new PrintStream(args[0]); } else { filePrintStream = System.out; } filePrintStream.printf("problem;mapper;genotypeSize;param;property;value%n"); //prepare distances Distance<Node<String>> phenotypeDistance = new CachedDistance<>(new LeavesEdit<String>()); Distance<Sequence> genotypeDistance = new CachedDistance<>(new Hamming()); //iterate for (String problemName : problems) { for (String mapperName : mappers) { System.out.printf("%20.20s, %20.20s", problemName, mapperName); //build problem Problem<String, NumericFitness> problem = null; if (problemName.equals("bool-parity5")) { problem = new Parity(5); } else if (problemName.equals("bool-mopm3")) { problem = new MultipleOutputParallelMultiplier(3); } else if (problemName.equals("sr-keijzer6")) { problem = new HarmonicCurve(); } else if (problemName.equals("sr-nguyen7")) { problem = new Nguyen7(1); } else if (problemName.equals("sr-pagie1")) { problem = new Pagie1(); } else if (problemName.equals("sr-vladislavleva4")) { problem = new Vladislavleva4(1); } else if (problemName.equals("other-klandscapes3")) { problem = new KLandscapes(3); } else if (problemName.equals("other-klandscapes7")) { problem = new KLandscapes(7); } else if (problemName.equals("other-text")) { problem = new Text(); } //build configuration and evolver Mapper mapper = null; int genotypeSize = Integer.parseInt(mapperName.split("-")[1]); int mapperMainParam = Integer.parseInt(mapperName.split("-")[2]); if (mapperName.split("-")[0].equals("ge")) { mapper = new StandardGEMapper<>(mapperMainParam, 1, problem.getGrammar()); } else if (mapperName.split("-")[0].equals("pige")) { mapper = new PiGEMapper<>(mapperMainParam, 1, problem.getGrammar()); } else if (mapperName.split("-")[0].equals("sge")) { mapper = new SGEMapper<>(mapperMainParam, problem.getGrammar()); } else if (mapperName.split("-")[0].equals("hge")) { mapper = new HierarchicalMapper<>(problem.getGrammar()); } else if (mapperName.split("-")[0].equals("whge")) { mapper = new WeightedHierarchicalMapper<>(mapperMainParam, false, true, problem.getGrammar()); } //prepare things Random random = new Random(1); Set<Sequence> genotypes = new LinkedHashSet<>(n); //build genotypes if (mapperName.split("-")[0].equals("sge")) { SGEGenotypeFactory<String> factory = new SGEGenotypeFactory<>((SGEMapper) mapper); while (genotypes.size() < n) { genotypes.add(factory.build(random)); } genotypeSize = factory.getBitSize(); } else { BitsGenotypeFactory factory = new BitsGenotypeFactory(genotypeSize); while (genotypes.size() < n) { genotypes.add(factory.build(random)); } } //build and fill map Multimap<Node<String>, Sequence> multimap = HashMultimap.create(); int progress = 0; for (Sequence genotype : genotypes) { Node<String> phenotype; try { if (mapperName.split("-")[0].equals("sge")) { phenotype = mapper.map((SGEGenotype<String>) genotype, new HashMap<>()); } else { phenotype = mapper.map((BitsGenotype) genotype, new HashMap<>()); } } catch (MappingException e) { phenotype = Node.EMPTY_TREE; } multimap.put(phenotype, genotype); progress = progress + 1; if (progress % Math.round(n / 10) == 0) { System.out.print("."); } } System.out.println(); //compute distances List<Pair<Double, Double>> allDistances = new ArrayList<>(); List<Pair<Double, Double>> allValidDistances = new ArrayList<>(); Multimap<Node<String>, Double> genotypeDistances = ArrayListMultimap.create(); for (Node<String> phenotype : multimap.keySet()) { for (Sequence genotype1 : multimap.get(phenotype)) { for (Sequence genotype2 : multimap.get(phenotype)) { double gDistance = genotypeDistance.d(genotype1, genotype2); genotypeDistances.put(phenotype, gDistance); if (genotypeDistances.get(phenotype).size() > nDist) { break; } } if (genotypeDistances.get(phenotype).size() > nDist) { break; } } } List<Map.Entry<Node<String>, Sequence>> entries = new ArrayList<>(multimap.entries()); Collections.shuffle(entries, random); for (Map.Entry<Node<String>, Sequence> entry1 : entries) { for (Map.Entry<Node<String>, Sequence> entry2 : entries) { double gDistance = genotypeDistance.d(entry1.getValue(), entry2.getValue()); double pDistance = phenotypeDistance.d(entry1.getKey(), entry2.getKey()); allDistances.add(new Pair<>(gDistance, pDistance)); if (!Node.EMPTY_TREE.equals(entry1.getKey()) && !Node.EMPTY_TREE.equals(entry2.getKey())) { allValidDistances.add(new Pair<>(gDistance, pDistance)); } if (allDistances.size() > nDist) { break; } } if (allDistances.size() > nDist) { break; } } //compute properties double invalidity = (double) multimap.get(Node.EMPTY_TREE).size() / (double) genotypes.size(); double redundancy = 1 - (double) multimap.keySet().size() / (double) genotypes.size(); double validRedundancy = redundancy; if (multimap.keySet().contains(Node.EMPTY_TREE)) { validRedundancy = 1 - ((double) multimap.keySet().size() - 1d) / (double) (genotypes.size() - multimap.get(Node.EMPTY_TREE).size()); } double locality = Utils.pearsonCorrelation(allDistances); double validLocality = Utils.pearsonCorrelation(allValidDistances); double[] sizes = new double[multimap.keySet().size()]; double[] meanGenotypeDistances = new double[multimap.keySet().size()]; int invalidIndex = -1; int c = 0; for (Node<String> phenotype : multimap.keySet()) { if (Node.EMPTY_TREE.equals(phenotype)) { invalidIndex = c; } sizes[c] = multimap.get(phenotype).size(); double[] distances = new double[genotypeDistances.get(phenotype).size()]; int k = 0; for (Double distance : genotypeDistances.get(phenotype)) { distances[k] = distance; k = k + 1; } meanGenotypeDistances[c] = StatUtils.mean(distances); c = c + 1; } double nonUniformity = Math.sqrt(StatUtils.variance(sizes)) / StatUtils.mean(sizes); double nonSynonymousity = StatUtils.mean(meanGenotypeDistances) / StatUtils.mean(firsts(allDistances)); double validNonUniformity = nonUniformity; double validNonSynonymousity = nonSynonymousity; if (invalidIndex != -1) { double[] validSizes = new double[multimap.keySet().size() - 1]; double[] validMeanGenotypeDistances = new double[multimap.keySet().size() - 1]; if (invalidIndex > 0) { System.arraycopy(sizes, 0, validSizes, 0, invalidIndex); System.arraycopy(meanGenotypeDistances, 0, validMeanGenotypeDistances, 0, invalidIndex); } System.arraycopy(sizes, invalidIndex + 1, validSizes, invalidIndex, sizes.length - invalidIndex - 1); System.arraycopy(meanGenotypeDistances, invalidIndex + 1, validMeanGenotypeDistances, invalidIndex, meanGenotypeDistances.length - invalidIndex - 1); validNonUniformity = Math.sqrt(StatUtils.variance(validSizes)) / StatUtils.mean(validSizes); validNonSynonymousity = StatUtils.mean(validMeanGenotypeDistances) / StatUtils.mean(firsts(allValidDistances)); } //compute locality filePrintStream.printf("%s;%s;%d;%d;invalidity;%f %n", problemName, mapperName.split("-")[0], genotypeSize, mapperMainParam, invalidity); filePrintStream.printf("%s;%s;%d;%d;redundancy;%f %n", problemName, mapperName.split("-")[0], genotypeSize, mapperMainParam, redundancy); filePrintStream.printf("%s;%s;%d;%d;validRedundancy;%f %n", problemName, mapperName.split("-")[0], genotypeSize, mapperMainParam, validRedundancy); filePrintStream.printf("%s;%s;%d;%d;locality;%f %n", problemName, mapperName.split("-")[0], genotypeSize, mapperMainParam, locality); filePrintStream.printf("%s;%s;%d;%d;validLLocality;%f %n", problemName, mapperName.split("-")[0], genotypeSize, mapperMainParam, validLocality); filePrintStream.printf("%s;%s;%d;%d;nonUniformity;%f %n", problemName, mapperName.split("-")[0], genotypeSize, mapperMainParam, nonUniformity); filePrintStream.printf("%s;%s;%d;%d;validNonUniformity;%f %n", problemName, mapperName.split("-")[0], genotypeSize, mapperMainParam, validNonUniformity); filePrintStream.printf("%s;%s;%d;%d;nonSynonymousity;%f %n", problemName, mapperName.split("-")[0], genotypeSize, mapperMainParam, nonSynonymousity); filePrintStream.printf("%s;%s;%d;%d;validNonSynonymousity;%f %n", problemName, mapperName.split("-")[0], genotypeSize, mapperMainParam, validNonSynonymousity); } } if (filePrintStream != null) { filePrintStream.close(); } }
From source file:com.yahoo.yqlplus.engine.tools.TraceFormatter.java
public static void dump(OutputStream outputStream, TraceRequest trace) throws IOException { Multimap<Integer, TraceEntry> childmap = ArrayListMultimap.create(); for (TraceEntry entry : trace.getEntries()) { childmap.put(entry.getParentId(), entry); }//w ww . java 2 s . c o m Multimap<Integer, TraceLogEntry> logmap = ArrayListMultimap.create(); for (TraceLogEntry entry : trace.getLog()) { logmap.put(entry.getTraceId(), entry); } CodeOutput out = new CodeOutput(); dumpTree(out, childmap, logmap, childmap.get(0)); outputStream.write(out.toString().getBytes(StandardCharsets.UTF_8)); }
From source file:com.github.drbookings.model.data.BookingMapFactory.java
public static Multimap<BookingBean, BookingEntry> buildMap(Collection<? extends BookingEntry> entries) { Multimap<BookingBean, BookingEntry> result = ArrayListMultimap.create(); for (BookingEntry be : entries) { result.put(be.getElement(), be); }/* www . ja va 2 s. c o m*/ return result; }
From source file:lu.list.itis.dkd.aig.CompositeVariable.java
public static Variable buildVariable(String label, String language, URI uri) throws TemplateParseException { ArrayListMultimap<String, String> parameters = ArrayListMultimap.create(); ArrayList<Value> values = new ArrayList<>(); Locale locale = Locale.forLanguageTag(language); parameters.put(Externalization.IDENTIFIER_ELEMENT, uri.toString()); parameters.put(Externalization.LANGUAGE_ELEMENT, locale.getLanguage()); parameters.put(Externalization.INITIALIZATION_ELEMENT, uri.toString()); values.add(new Value(uri, ValueType.TEXT, label)); Variable variable = new Variable(parameters, values); return variable; }
From source file:com.spectralogic.ds3client.helpers.JobPartTrackerFactory.java
public static JobPartTracker buildPartTracker(final Iterable<BulkObject> objects) { final ArrayListMultimap<String, ObjectPart> multimap = ArrayListMultimap.create(); for (final BulkObject bulkObject : Preconditions.checkNotNull(objects)) { multimap.put(bulkObject.getName(), new ObjectPart(bulkObject.getOffset(), bulkObject.getLength())); }//from w w w . j a v a 2s .co m return new JobPartTrackerImpl(new HashMap<>( Maps.transformEntries(multimap.asMap(), new BuildObjectPartTrackerFromObjectPartGroup()))); }
From source file:io.crate.execution.dsl.phases.NodeOperationGrouper.java
public static Map<String, Collection<NodeOperation>> groupByServer(Iterable<NodeOperation> nodeOperations) { ArrayListMultimap<String, NodeOperation> byServer = ArrayListMultimap.create(); for (NodeOperation nodeOperation : nodeOperations) { for (String server : nodeOperation.executionPhase().nodeIds()) { byServer.put(server, nodeOperation); }//from ww w . ja va 2 s. c om } return byServer.asMap(); }