List of usage examples for java.util List equals
boolean equals(Object o);
From source file:org.gvnix.web.screen.roo.addon.AbstractPatternMetadata.java
/** * Returns the method if exists or null otherwise. With this we assure that * a method is defined once in the Class * //from ww w . java 2s . c om * @param methodName * @param paramTypes * @return */ protected MethodMetadata methodExists(JavaSymbolName methodName, List<AnnotatedJavaType> paramTypes) { List<JavaType> nonAnnotatedJavaTypes = AnnotatedJavaType.convertFromAnnotatedJavaTypes(paramTypes); for (MethodMetadata methodMetadata : controllerMethods) { if (methodMetadata.getMethodName().equals(methodName) && nonAnnotatedJavaTypes .equals(AnnotatedJavaType.convertFromAnnotatedJavaTypes(methodMetadata.getParameterTypes()))) { return methodMetadata; } } return null; }
From source file:femr.util.startup.MedicationDatabaseSeeder.java
/** * Puts a concept medication together for adding. * * @param conceptMedications a list of all currently available concept medications to compare against exisiting ones, not null * @param conceptMedicationFormMap a map of all medication forms available, not null * @param conceptMedicationGenericStrengths a list of the generic medications for the new concept, not null * @param brandName brand name of the new medication, may be null * @param form form of the new medication, may be null * @return a new ConceptMedication or null if errors or null if the concept medication already exists *//* w w w . j a v a2 s.c o m*/ private ConceptMedication addConceptMedication(List<? extends IMedication> conceptMedications, Map<String, Integer> conceptMedicationFormMap, List<IMedicationGenericStrength> conceptMedicationGenericStrengths, String brandName, String form) { if (conceptMedications == null || conceptMedicationFormMap == null || conceptMedicationGenericStrengths == null) { return null; } //sort by primary key to get an order that works for comparing Collections.sort(conceptMedicationGenericStrengths, (o1, o2) -> ((Integer) o1.getId()).compareTo(o2.getId())); //compare all of the medications for (IMedication medication : conceptMedications) { List<IMedicationGenericStrength> medicationGenericStrengths = medication .getMedicationGenericStrengths(); Collections.sort(medicationGenericStrengths, (o1, o2) -> ((Integer) o1.getId()).compareTo(o2.getId())); if (medicationGenericStrengths.equals(conceptMedicationGenericStrengths) && medication.getName().equals(brandName) && medication.getConceptMedicationForm() != null && medication.getConceptMedicationForm().getName().equals(form)) { return null; } } ConceptMedication conceptMedication = new ConceptMedication(); conceptMedication.setName(brandName); conceptMedication.setConceptMedicationForm( Ebean.getReference(ConceptMedicationForm.class, conceptMedicationFormMap.get(form))); conceptMedicationGenericStrengths.removeIf(Objects::isNull); conceptMedication.setMedicationGenericStrengths(conceptMedicationGenericStrengths); conceptMedication.setIsDeleted(false); if (conceptMedication.getMedicationGenericStrengths().size() > 0) conceptMedication.setMedicationGenericStrengths(conceptMedicationGenericStrengths); else conceptMedication = null; return conceptMedication; }
From source file:com.ciphertool.genetics.algorithms.mutation.LiberalMutationAlgorithmTest.java
@Test public void testMutateChromosomeLessThanTargetSize() { liberalMutationAlgorithm.setMaxMutationsPerChromosome(MAX_MUTATIONS); MockKeylessChromosome mockKeylessChromosome = new MockKeylessChromosome(); mockKeylessChromosome.setTargetSize(6); List<Gene> originalGenes = new ArrayList<Gene>(); MockGene mockGene1 = new MockGene(); mockGene1.addSequence(new MockSequence("a")); mockGene1.addSequence(new MockSequence("b")); mockGene1.addSequence(new MockSequence("c")); mockKeylessChromosome.addGene(mockGene1); originalGenes.add(mockGene1);/*from www . ja v a 2s. c o m*/ MockGene mockGene2 = new MockGene(); mockGene2.addSequence(new MockSequence("1")); mockGene2.addSequence(new MockSequence("2")); mockGene2.addSequence(new MockSequence("3")); mockKeylessChromosome.addGene(mockGene2); originalGenes.add(mockGene2); MockGene mockGeneToReturn = new MockGene(); mockGeneToReturn.addSequence(new MockSequence("w")); mockGeneToReturn.addSequence(new MockSequence("x")); when(geneDaoMock.findRandomGene(same(mockKeylessChromosome))).thenReturn(mockGeneToReturn.clone(), mockGeneToReturn.clone()); MockGene fillerGeneToReturn = new MockGene(); fillerGeneToReturn.addSequence(new MockSequence("y")); fillerGeneToReturn.addSequence(new MockSequence("z")); when(geneDaoMockForChromosomeHelper.findRandomGene(same(mockKeylessChromosome))) .thenReturn(fillerGeneToReturn.clone(), fillerGeneToReturn.clone()); assertEquals(2, mockKeylessChromosome.getGenes().size()); liberalMutationAlgorithm.mutateChromosome(mockKeylessChromosome); assertFalse(originalGenes.equals(mockKeylessChromosome.getGenes())); assertTrue(mockKeylessChromosome.getGenes().size() >= 3); assertEquals(new Integer(6), mockKeylessChromosome.actualSize()); // The last Sequence(s) should always be from the KeylessChromosomeHelper assertEquals("y", ((VariableLengthGene) mockKeylessChromosome.getGenes().get(2)).getSequences().get(0).getValue()); verify(geneDaoMock, atLeast(1)).findRandomGene(same(mockKeylessChromosome)); verify(geneDaoMock, atMost(2)).findRandomGene(same(mockKeylessChromosome)); verify(geneDaoMockForChromosomeHelper, atLeast(1)).findRandomGene(same(mockKeylessChromosome)); verify(geneDaoMockForChromosomeHelper, atMost(2)).findRandomGene(same(mockKeylessChromosome)); verify(chromosomeHelperSpy, atLeastOnce()).resizeChromosome(same(mockKeylessChromosome)); verify(chromosomeHelperSpy, atMost(2)).resizeChromosome(same(mockKeylessChromosome)); verifyZeroInteractions(logMock); }
From source file:jenkins.scm.impl.subversion.SubversionSCMSource.java
void fetch(@NonNull TaskListener listener, @NonNull final SVNRepositoryView repository, long rev, @NonNull final String repoPath, @NonNull SortedSet<List<String>> paths, @NonNull List<String> prefix, @NonNull List<String> realPath, @NonNull SortedSet<List<String>> excludedPaths, @CheckForNull SCMSourceCriteria branchCriteria, @NonNull SCMHeadObserver observer) throws IOException, SVNException { String svnPath = SVNPathUtil.append(repoPath, StringUtils.join(realPath, '/')); assert prefix.size() == realPath.size(); assert wildcardStartsWith(realPath, prefix); SortedMap<List<String>, SortedSet<List<String>>> includePaths = groupPaths(paths, prefix); listener.getLogger().println("Checking directory " + svnPath + (rev > -1 ? "@" + rev : "@HEAD")); SVNRepositoryView.NodeEntry node = repository.getNode(svnPath, rev); if (!SVNNodeKind.DIR.equals(node.getType()) || node.getChildren() == null) { return;//from w w w . j ava2 s .c o m } for (Map.Entry<List<String>, SortedSet<List<String>>> entry : includePaths.entrySet()) { for (List<String> path : entry.getValue()) { String name = path.get(prefix.size()); SVNRepositoryView.ChildEntry[] children = node.getChildren().clone(); Arrays.sort(children, new Comparator<SVNRepositoryView.ChildEntry>() { public int compare(SVNRepositoryView.ChildEntry o1, SVNRepositoryView.ChildEntry o2) { long diff = o2.getRevision() - o1.getRevision(); return diff < 0 ? -1 : diff > 0 ? 1 : 0; } }); for (final SVNRepositoryView.ChildEntry svnEntry : children) { if (svnEntry.getType() == SVNNodeKind.DIR && isMatch(svnEntry.getName(), name)) { List<String> childPrefix = copyAndAppend(prefix, name); List<String> childRealPath = copyAndAppend(realPath, svnEntry.getName()); if (wildcardStartsWith(childRealPath, excludedPaths)) { continue; } if (path.equals(childPrefix)) { final String childPath = StringUtils.join(childRealPath, '/'); final String candidateRootPath = SVNPathUtil.append(repoPath, childPath); final long candidateRevision = svnEntry.getRevision(); final long lastModified = svnEntry.getLastModified(); listener.getLogger().println( "Checking candidate branch " + candidateRootPath + "@" + candidateRevision); if (branchCriteria == null || branchCriteria.isHead(new SCMSourceCriteria.Probe() { @Override public String name() { return childPath; } @Override public long lastModified() { return lastModified; } @Override public boolean exists(@NonNull String path) throws IOException { try { return repository.checkPath(SVNPathUtil.append(candidateRootPath, path), candidateRevision) != SVNNodeKind.NONE; } catch (SVNException e) { throw new IOException(e); } } }, listener)) { listener.getLogger().println("Met criteria"); SCMHead head = new SCMHead(childPath); observer.observe(head, new SCMRevisionImpl(head, svnEntry.getRevision())); if (!observer.isObserving()) { return; } } else { listener.getLogger().println("Does not meet criteria"); } } else { fetch(listener, repository, svnEntry.getRevision(), repoPath, paths, childPrefix, childRealPath, excludedPaths, branchCriteria, observer); } } } } } }
From source file:com.pivotal.hawq.mapreduce.TPCHLocalTester.java
@Override protected void testTPCHTable(HAWQTPCHSpec tpchSpec, String tableName) throws Exception { String caseName = tpchSpec.toString(); final File caseFolder = new File(TEST_FOLDER, caseName); final File metadataFile = new File(caseFolder, tableName + ".yaml"); final File answerFile = new File(caseFolder, tableName + ".ans"); final File outputFile = new File(caseFolder, "output/part-r-00000"); List<String> answers; if (caseFolder.exists()) { answers = Files.readLines(answerFile, Charsets.UTF_8); } else {/*from w ww.ja v a 2 s . c o m*/ caseFolder.mkdir(); Connection conn = null; try { conn = MRFormatTestUtils.getTestDBConnection(); // load TPCH data Map<String, String> rs = HAWQJdbcUtils.executeSafeQueryForSingleRow(conn, "SELECT COUNT(*) segnum FROM gp_segment_configuration WHERE content>=0;"); int segnum = Integer.parseInt(rs.get("segnum")); MRFormatTestUtils.runShellCommand(tpchSpec.getLoadCmd(segnum)); // generate answer answers = MRFormatTestUtils.dumpTable(conn, tableName); Collections.sort(answers); Files.write(Joiner.on('\n').join(answers).getBytes(), answerFile); // extract metadata MRFormatTestUtils.runShellCommand( String.format("gpextract -d %s -o %s %s", TEST_DB_NAME, metadataFile.getPath(), tableName)); // copy data files to local MRFormatTestUtils.copyDataFilesToLocal(metadataFile); // transform metadata file to use local file locations MRFormatTestUtils.transformMetadata(metadataFile); } catch (Exception e) { // clean up if any error happens FileUtils.deleteDirectory(caseFolder); throw e; } finally { HAWQJdbcUtils.closeConnection(conn); } } // run input format driver int exitCode = MRFormatTestUtils.runMapReduceLocally(new Path(metadataFile.getPath()), new Path(outputFile.getParent()), null); Assert.assertEquals(0, exitCode); // compare result List<String> outputs = Files.readLines(outputFile, Charsets.UTF_8); if (!answers.equals(outputs)) Assert.fail(String.format("HAWQInputFormat output for table %s differs with DB output:\n%s\n%s", tableName, answerFile, outputFile)); }
From source file:com.emc.storageos.coordinator.client.service.impl.CoordinatorClientImpl.java
/** * Common method to compare available versions with target's available versions * //from ww w . j a v a 2 s .com * @param targetGiven * target repository * @param infos * nodes' repository * @return list of nodes which available versions are different from the target's */ private List<String> getDifferentVersionsCommon(final RepositoryInfo targetGiven, final Map<Service, RepositoryInfo> infos) { List<String> differentVersions = new ArrayList<String>(); final List<SoftwareVersion> targetVersions = targetGiven.getVersions(); for (Map.Entry<Service, RepositoryInfo> entry : infos.entrySet()) { if (!targetVersions.equals(entry.getValue().getVersions())) { differentVersions.add(entry.getKey().getId()); } } return differentVersions; }
From source file:com.net2plan.libraries.IPUtils.java
/** * Computes the routing table matrix according to an OSPF/ECMP scheme. For * each destination node <i>t</i>, and each link <i>e</i>, {@code f_te[t][e]} * sets the fraction of the traffic targeted to node <i>t</i> that arrives * (or is generated in) node <i>a(e)</i> (the initial node of link <i>e</i>), * that is forwarded through link <i>e</i>. It must hold that for every * node <i>n</i> different of <i>t</i>, the sum of the fractions * <i>f<sub>te</sub></i> along its outgoing links must be 1. For every * destination <i>t</i>, <i>f<sub>te</sub></i> = 0 for all the links <i>e</i> * that are outgoing links of <i>t</i>. * @param nodes List of nodes//from www.j ava 2 s .c o m * @param links List of links * @param linkWeightVector Cost per link vector * @return Destination-based routing in the form <i>f<sub>te</sub></i> (fractions of traffic in a node, that is forwarded through each of its output links to node {@code t}) */ public static DoubleMatrix2D computeECMPRoutingTableMatrix_fte(List<Node> nodes, List<Link> links, DoubleMatrix1D linkWeightVector) { final int N = nodes.size(); final int E = links.size(); DoubleMatrix2D f_te = DoubleFactory2D.sparse.make(N, E); double[][] costMatrix = new double[N][N]; for (int n = 0; n < N; n++) { Arrays.fill(costMatrix[n], Double.MAX_VALUE); costMatrix[n][n] = 0; } Map<Link, Double> linkWeightMap = CollectionUtils.toMap(links, linkWeightVector); Transformer<Link, Double> nev = JUNGUtils.getEdgeWeightTransformer(linkWeightMap); Map<Pair<Node, Node>, Set<Link>> linksPerNodePair = new LinkedHashMap<Pair<Node, Node>, Set<Link>>(); for (Link link : links) { final int a_e = link.getOriginNode().getIndex(); final int b_e = link.getDestinationNode().getIndex(); costMatrix[a_e][b_e] = Math.min(costMatrix[a_e][b_e], nev.transform(link)); Pair<Node, Node> nodePair_thisLink = Pair.of(link.getOriginNode(), link.getDestinationNode()); Set<Link> links_thisNodePair = linksPerNodePair.get(nodePair_thisLink); if (links_thisNodePair == null) { links_thisNodePair = new LinkedHashSet<Link>(); linksPerNodePair.put(nodePair_thisLink, links_thisNodePair); } links_thisNodePair.add(link); } for (int k = 0; k < N; k++) { for (int i = 0; i < N; i++) { if (i == k) continue; for (int j = 0; j < N; j++) { if (j == k || j == i) continue; double newValue = costMatrix[i][k] + costMatrix[k][j]; if (newValue < costMatrix[i][j]) costMatrix[i][j] = newValue; } } } for (Node egressNode : nodes) { final int t = egressNode.getIndex(); for (Node node : nodes) { final int n = node.getIndex(); if (n == t) continue; double distNodeToEgress = costMatrix[n][t]; if (distNodeToEgress == Double.MAX_VALUE) continue; Set<Link> A_t = new LinkedHashSet<Link>(); for (Node intermediateNode : nodes) { if (nodes.equals(intermediateNode)) continue; final int m = intermediateNode.getIndex(); double distIntermediateToEgress = costMatrix[m][t]; if (distIntermediateToEgress == Double.MAX_VALUE) continue; Collection<Link> linksFromNodeToIntermediate = linksPerNodePair .get(Pair.of(node, intermediateNode)); if (linksFromNodeToIntermediate == null) continue; for (Link link : linksFromNodeToIntermediate) { double weight_thisLink = linkWeightMap.get(link); checkIPWeight(weight_thisLink); if (Math.abs(weight_thisLink - (distNodeToEgress - distIntermediateToEgress)) < 1E-10) A_t.add(link); } } int outdegree = A_t.size(); if (outdegree > 0) for (Link link : A_t) f_te.set(t, link.getIndex(), 1.0 / outdegree); } } return f_te; }
From source file:nl.inl.blacklab.search.HitsImpl.java
/** * Retrieve context words for the hits./* w w w.j a v a 2s. c o m*/ * * @param fieldProps * the field and properties to use for the context */ @Override public synchronized void findContext(List<String> fieldProps) { try { ensureAllHitsRead(); } catch (InterruptedException e) { // Thread was interrupted. Just go ahead with the hits we did // get, so at least we can return with valid context. Thread.currentThread().interrupt(); } // Make sure we don't have the desired context already if (contextFieldsPropName != null && fieldProps.equals(contextFieldsPropName) && settings().contextSize() == currentContextSize) { return; } List<ForwardIndex> fis = new ArrayList<>(); for (String fieldPropName : fieldProps) { fis.add(searcher.getForwardIndex(fieldPropName)); } // Get the context // Group hits per document List<Hit> hitsInSameDoc = new ArrayList<>(); int currentDoc = -1; int index = 0; if (contexts == null || contexts.length < hits.size()) { contexts = new int[hits.size()][]; } for (Hit hit : hits) { if (hit.doc != currentDoc) { if (currentDoc >= 0) { try { etiquette.behave(); } catch (InterruptedException e) { // Thread was interrupted. Just go ahead with the hits we did // get, so at least we can return with valid context. Thread.currentThread().interrupt(); } findPartOfContext(hitsInSameDoc, index - hitsInSameDoc.size(), fis); // Reset hits list for next doc hitsInSameDoc.clear(); } currentDoc = hit.doc; // start a new document } hitsInSameDoc.add(hit); index++; } if (!hitsInSameDoc.isEmpty()) findPartOfContext(hitsInSameDoc, index - hitsInSameDoc.size(), fis); currentContextSize = settings().contextSize(); contextFieldsPropName = new ArrayList<>(fieldProps); }
From source file:com.ciphertool.genetics.algorithms.mutation.LiberalMutationAlgorithmTest.java
@Test public void testMutateRandomGeneBoundaryConditions() { MockKeylessChromosome mockKeylessChromosome = new MockKeylessChromosome(); mockKeylessChromosome.setTargetSize(2); List<Gene> originalGenes = new ArrayList<Gene>(); MockGene mockGene1 = new MockGene(); mockGene1.addSequence(new MockSequence("a")); originalGenes.add(mockGene1);/*from ww w. ja va 2 s .c om*/ MockGene mockGene2 = new MockGene(); mockGene2.addSequence(new MockSequence("b")); originalGenes.add(mockGene2); MockGene mockGeneToReturn = new MockGene(); mockGeneToReturn.addSequence(new MockSequence("1")); mockGeneToReturn.addSequence(new MockSequence("2")); List<Integer> availableIndices = new ArrayList<Integer>(); do { mockKeylessChromosome.setFitness(0.0); while (!mockKeylessChromosome.getGenes().isEmpty()) { mockKeylessChromosome.removeGene(mockKeylessChromosome.getGenes().size() - 1); } mockKeylessChromosome.addGene(mockGene1); mockKeylessChromosome.addGene(mockGene2); availableIndices.clear(); availableIndices.add(0); availableIndices.add(1); when(geneDaoMock.findRandomGene(any(Chromosome.class))).thenReturn(mockGeneToReturn.clone()); liberalMutationAlgorithm.mutateRandomGene(mockKeylessChromosome, availableIndices); /* * If the availableIndices List does not contain the last element, * we need to repeat, because that does not trigger the specific * scenario we are testing for. */ } while (availableIndices.size() > 0 && (availableIndices.get(availableIndices.size() - 1) == 0)); /* * Only one Gene should be mutated. */ assertFalse(originalGenes.equals(mockKeylessChromosome.getGenes())); assertEquals(0, availableIndices.size()); verify(geneDaoMock, atLeastOnce()).findRandomGene(same(mockKeylessChromosome)); verify(chromosomeHelperSpy, atLeastOnce()).resizeChromosome(same(mockKeylessChromosome)); verifyZeroInteractions(logMock); }