List of usage examples for org.apache.commons.collections CollectionUtils intersection
public static Collection intersection(final Collection a, final Collection b)
From source file:org.apache.solr.cloud.RollingRestartTest.java
public void restartWithRolesTest() throws Exception { String leader = OverseerCollectionConfigSetProcessor .getLeaderNode(cloudClient.getZkStateReader().getZkClient()); assertNotNull(leader);/*from www.j ava 2 s. c om*/ log.info("Current overseer leader = {}", leader); cloudClient.getZkStateReader().getZkClient().printLayoutToStdOut(); int numDesignateOverseers = TEST_NIGHTLY ? 16 : 2; numDesignateOverseers = Math.max(getShardCount(), numDesignateOverseers); List<String> designates = new ArrayList<>(); List<CloudJettyRunner> designateJettys = new ArrayList<>(); for (int i = 0; i < numDesignateOverseers; i++) { int n = random().nextInt(getShardCount()); String nodeName = cloudJettys.get(n).nodeName; log.info("Chose {} as overseer designate", nodeName); new CollectionAdminRequest.AddRole().setRole("overseer").setNode(nodeName).process(cloudClient); designates.add(nodeName); designateJettys.add(cloudJettys.get(n)); } waitUntilOverseerDesignateIsLeader(cloudClient.getZkStateReader().getZkClient(), designates, MAX_WAIT_TIME); cloudClient.getZkStateReader().getZkClient().printLayoutToStdOut(); boolean sawLiveDesignate = false; int numRestarts = 1 + random().nextInt(TEST_NIGHTLY ? 12 : 2); for (int i = 0; i < numRestarts; i++) { log.info("Rolling restart #{}", i + 1); for (CloudJettyRunner cloudJetty : designateJettys) { log.info("Restarting {}", cloudJetty); chaosMonkey.stopJetty(cloudJetty); cloudClient.getZkStateReader().updateLiveNodes(); boolean liveDesignates = CollectionUtils .intersection(cloudClient.getZkStateReader().getClusterState().getLiveNodes(), designates) .size() > 0; if (liveDesignates) { sawLiveDesignate = true; boolean success = waitUntilOverseerDesignateIsLeader( cloudClient.getZkStateReader().getZkClient(), designates, MAX_WAIT_TIME); if (!success) { leader = OverseerCollectionConfigSetProcessor .getLeaderNode(cloudClient.getZkStateReader().getZkClient()); if (leader == null) log.error("NOOVERSEER election queue is :" + OverseerCollectionConfigSetProcessor .getSortedElectionNodes(cloudClient.getZkStateReader().getZkClient(), "/overseer_elect/election")); fail("No overseer designate as leader found after restart #" + (i + 1) + ": " + leader); } } assertTrue("Unable to restart (#" + i + "): " + cloudJetty, ChaosMonkey.start(cloudJetty.jetty)); boolean success = waitUntilOverseerDesignateIsLeader(cloudClient.getZkStateReader().getZkClient(), designates, MAX_WAIT_TIME); if (!success) { leader = OverseerCollectionConfigSetProcessor .getLeaderNode(cloudClient.getZkStateReader().getZkClient()); if (leader == null) log.error("NOOVERSEER election queue is :" + OverseerCollectionConfigSetProcessor.getSortedElectionNodes( cloudClient.getZkStateReader().getZkClient(), "/overseer_elect/election")); fail("No overseer leader found after restart #" + (i + 1) + ": " + leader); } cloudClient.getZkStateReader().updateLiveNodes(); sawLiveDesignate = CollectionUtils .intersection(cloudClient.getZkStateReader().getClusterState().getLiveNodes(), designates) .size() > 0; } } assertTrue("Test may not be working if we never saw a live designate", sawLiveDesignate); leader = OverseerCollectionConfigSetProcessor.getLeaderNode(cloudClient.getZkStateReader().getZkClient()); assertNotNull(leader); log.info("Current overseer leader (after restart) = {}", leader); cloudClient.getZkStateReader().getZkClient().printLayoutToStdOut(); }
From source file:org.apache.uima.ruta.action.GatherAction.java
private void gatherFeatures(TOP structure, Map<IStringExpression, IRutaExpression> features, AnnotationFS matchedAnnotation, RuleElement element, RuleMatch match, RutaStream stream) { Map<String, List<Number>> map = new HashMap<String, List<Number>>(); for (Entry<IStringExpression, IRutaExpression> each : features.entrySet()) { RutaBlock parent = element.getParent(); String value = each.getKey().getStringValue(parent, match, element, stream); IRutaExpression expr = each.getValue(); List<Number> ints = new ArrayList<Number>(); if (expr instanceof INumberExpression) { INumberExpression ne = (INumberExpression) expr; ints.add(ne.getIntegerValue(parent, match, element, stream)); map.put(value, ints);/* w w w . ja v a2 s.c om*/ } else if (expr instanceof NumberListExpression) { NumberListExpression ne = (NumberListExpression) expr; map.put(value, ne.getList(parent, stream)); } } TypeSystem typeSystem = stream.getCas().getTypeSystem(); JCas jcas = stream.getJCas(); List<?> featuresList = structure.getType().getFeatures(); for (int i = 0; i < featuresList.size(); i++) { Feature targetFeature = (Feature) featuresList.get(i); String name = targetFeature.getName(); String shortFName = name.substring(name.indexOf(":") + 1, name.length()); List<Number> reIndexes = map.get(shortFName); if (reIndexes != null && !reIndexes.isEmpty()) { Type range = targetFeature.getRange(); List<RuleElementMatch> tms = getMatchInfo(match, element, reIndexes); if (tms.size() == 0) {// do nothing } else if (tms.size() == 1) { RuleElementMatch tm = tms.get(0); List<AnnotationFS> textsMatched = tm.getTextsMatched(); if (textsMatched.size() == 1) { AnnotationFS fs = textsMatched.get(0); if (typeSystem.subsumes(jcas.getCasType(FSArray.type), range)) { List<AnnotationFS> list = new ArrayList<AnnotationFS>(); list.add(fs); structure.setFeatureValue(targetFeature, UIMAUtils.toFSArray(jcas, list)); } else if (typeSystem.subsumes(range, fs.getType())) { structure.setFeatureValue(targetFeature, fs); } else { // search for Collection<AnnotationFS> beginAnchors = stream.getBeginAnchor(fs.getBegin()) .getBeginAnchors(range); Collection<AnnotationFS> endAnchors = stream.getEndAnchor(fs.getEnd()) .getEndAnchors(range); @SuppressWarnings("unchecked") Collection<AnnotationFS> intersection = CollectionUtils.intersection(beginAnchors, endAnchors); if (intersection.size() >= 1) { structure.setFeatureValue(targetFeature, intersection.iterator().next()); } } } } else { List<AnnotationFS> textsMatched = getMatchedText(tms); if (typeSystem.subsumes(jcas.getCasType(FSArray.type), range)) { structure.setFeatureValue(targetFeature, UIMAUtils.toFSArray(jcas, textsMatched)); } else { int begin = textsMatched.get(0).getBegin(); int end = textsMatched.get(textsMatched.size() - 1).getEnd(); RutaFrame frame = new RutaFrame(jcas, begin, end); FSIterator<Annotation> iterator = jcas.getAnnotationIndex(range).iterator(frame); AnnotationFS newA = null; while (iterator.isValid()) { Annotation a = iterator.get(); if (a.getBegin() == begin && a.getEnd() == end && jcas.getTypeSystem().subsumes(range, a.getType())) { newA = a; } else if (a.getBegin() > begin || a.getEnd() < end) { break; } iterator.moveToNext(); } if (newA == null) { newA = jcas.getCas().createAnnotation(range, begin, end); } structure.setFeatureValue(targetFeature, newA); } } } } }
From source file:org.apache.uima.ruta.action.ImplicitFeatureAction.java
private List<AnnotationFS> getAnnotations(AnnotationFS annotation, Type type, FeatureMatchExpression fme, RutaStream stream) {/*from w ww. j a va 2 s . co m*/ List<AnnotationFS> result = new ArrayList<AnnotationFS>(); TypeSystem typeSystem = stream.getCas().getTypeSystem(); if (typeSystem.subsumes(type, annotation.getType())) { result.add(annotation); } else { Collection<AnnotationFS> beginAnchors = stream.getBeginAnchor(annotation.getBegin()) .getBeginAnchors(type); Collection<AnnotationFS> endAnchors = stream.getEndAnchor(annotation.getEnd()).getEndAnchors(type); @SuppressWarnings("unchecked") Collection<AnnotationFS> intersection = CollectionUtils.intersection(beginAnchors, endAnchors); result.addAll(intersection); } return result; }
From source file:org.apache.uima.ruta.condition.ImplicitCondition.java
private List<AnnotationFS> getAnnotationsToCheck(AnnotationFS annotation, Type type, FeatureMatchExpression fme, RutaStream stream) {/*from www . j ava 2 s .co m*/ List<AnnotationFS> result = new ArrayList<AnnotationFS>(); TypeSystem typeSystem = stream.getCas().getTypeSystem(); if (typeSystem.subsumes(type, annotation.getType())) { result.add(annotation); } else { Collection<AnnotationFS> beginAnchors = stream.getBeginAnchor(annotation.getBegin()) .getBeginAnchors(type); Collection<AnnotationFS> endAnchors = stream.getEndAnchor(annotation.getEnd()).getEndAnchors(type); @SuppressWarnings("unchecked") Collection<AnnotationFS> intersection = CollectionUtils.intersection(beginAnchors, endAnchors); result.addAll(intersection); } return result; }
From source file:org.apache.uima.ruta.expression.RutaExpression.java
protected List<AnnotationFS> getTargetAnnotation(AnnotationFS annotation, Type type, RutaStream stream) { if (annotation == null) { return Collections.emptyList(); }//from w ww . j a v a 2s . c o m // "autocast" to document annotation when mentioning document. // This is either the actual document annotation or the current one in a block or inlined rule AnnotationFS documentAnnotation = stream.getCas().getDocumentAnnotation(); Type docType = documentAnnotation.getType(); if (docType.equals(type)) { List<AnnotationFS> result = new ArrayList<AnnotationFS>(1); AnnotationFS windowAnnotation = stream.getFilter().getWindowAnnotation(); if (windowAnnotation == null) { result.add(documentAnnotation); return result; } else { result.add(windowAnnotation); return result; } } if (annotation.getType().equals(type) || stream.getCas().getTypeSystem().subsumes(type, annotation.getType())) { List<AnnotationFS> result = new ArrayList<AnnotationFS>(1); result.add(annotation); return result; } else { Collection<AnnotationFS> beginAnchors = stream.getBeginAnchor(annotation.getBegin()) .getBeginAnchors(type); Collection<AnnotationFS> endAnchors = stream.getEndAnchor(annotation.getEnd()).getEndAnchors(type); @SuppressWarnings("unchecked") Collection<AnnotationFS> intersection = CollectionUtils.intersection(beginAnchors, endAnchors); return new ArrayList<AnnotationFS>(intersection); } }
From source file:org.beanfuse.lang.SeqStringUtil.java
/** * ???a-b//from w ww . j a va 2 s . com * * @param first * @param second * @param delimiter * @return */ public static String intersectSeq(final String first, final String second, final String delimiter) { if (StringUtils.isEmpty(first) || StringUtils.isEmpty(second)) { return ""; } List firstSeq = Arrays.asList(StringUtils.split(first, ",")); List secondSeq = Arrays.asList(StringUtils.split(second, ",")); Collection rs = CollectionUtils.intersection(firstSeq, secondSeq); StringBuilder buf = new StringBuilder(); for (Iterator iter = rs.iterator(); iter.hasNext();) { String ele = (String) iter.next(); buf.append(delimiter).append(ele); } if (buf.length() > 0) { buf.append(delimiter); } return buf.toString(); }
From source file:org.beangle.commons.lang.StrUtils.java
/** * ???a-b//from ww w . ja v a 2s . c o m * * @param first * @param second * @param delimiter * @return */ public static String intersectSeq(final String first, final String second, final String delimiter) { if (StringUtils.isEmpty(first) || StringUtils.isEmpty(second)) { return ""; } List<String> firstSeq = Arrays.asList(StringUtils.split(first, ",")); List<String> secondSeq = Arrays.asList(StringUtils.split(second, ",")); @SuppressWarnings("unchecked") Collection<String> rs = CollectionUtils.intersection(firstSeq, secondSeq); StringBuilder buf = new StringBuilder(); for (final String ele : rs) { buf.append(delimiter).append(ele); } if (buf.length() > 0) { buf.append(delimiter); } return buf.toString(); }
From source file:org.bigwiv.blastgraph.command.RemoveSingleLinkageCommand.java
private boolean isSingle(ValueEdge valueEdge, BlastGraph<HitVertex, ValueEdge> graph) { Pair<HitVertex> pair = graph.getEndpoints(valueEdge); Collection<HitVertex> vertices1 = graph.getNeighbors(pair.getFirst()); Collection<HitVertex> vertices2 = graph.getNeighbors(pair.getSecond()); Collection<HitVertex> union = CollectionUtils.intersection(vertices1, vertices2); //System.out.println(vertices1.size() + " " + vertices2.size() + " " + union.size()); if (union.isEmpty()) { return true; } else {/*from ww w . j a va2 s . c o m*/ return false; } }
From source file:org.bigwiv.blastgraph.command.TaxonFiltCommand.java
private boolean isSingle(ValueEdge valueEdge, BlastGraph<HitVertex, ValueEdge> graph) { Pair<HitVertex> pair = graph.getEndpoints(valueEdge); Collection<HitVertex> vertices1 = graph.getNeighbors(pair.getFirst()); Collection<HitVertex> vertices2 = graph.getNeighbors(pair.getSecond()); Collection<HitVertex> union = CollectionUtils.intersection(vertices1, vertices2); //System.out.println(vertices1.size() + " " + vertices2.size() + " " + union.size()); if (union.size() * 1.0 / Math.min(vertices1.size(), vertices2.size()) < 0.1) { return true; } else {/*from w ww .jav a 2s .c o m*/ return false; } }
From source file:org.bigwiv.blastgraph.gui.BlastGraphFrame.java
private void refreshColorControl() { // find the minimal taxon length and attribute key collection Collection<HitVertex> hvs = Global.graph.getVertices(); int minTaxon = 0; Collection<String> minKeySet = new HashSet<String>(); for (HitVertex hitVertex : hvs) { int value = hitVertex.getTaxon().getLevels(); Set<String> keySet = hitVertex.getAllAttributes().keySet(); if (minTaxon == 0) { minTaxon = value;//from www . j a v a 2 s. c om minKeySet = keySet; } else { minTaxon = value < minTaxon ? value : minTaxon; minKeySet = CollectionUtils.intersection(minKeySet, keySet); } } // clear taxons and attrs // final int seleceted = colorComboBox.getSelectedIndex(); for (int i = colorComboBox.getItemCount() - 1; i >= 5; i--) { colorComboBox.removeItemAt(i); } // add taxons for (int i = 0; i < minTaxon; i++) { colorComboBox.addItem("taxon" + i); } // add attrs for (String string : minKeySet) { colorComboBox.addItem(string); } colorComboBox.setSelectedIndex(0); final int min = minTaxon; if (colorItemListener != null) { colorComboBox.removeItemListener(colorItemListener); } colorItemListener = new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { int index = colorComboBox.getSelectedIndex(); String attr = (String) colorComboBox.getSelectedItem(); ArrayList<String> attrValues = new ArrayList<String>(); Map<String, Color> colorMap = new HashMap<String, Color>(); Collection<HitVertex> hvs = Global.graph.getVertices(); String value = ""; if (index != 0) { for (HitVertex hitVertex : hvs) { if (index < 5) { switch (index) { case 1: value = hitVertex.getIndex() + ""; break; case 2: value = hitVertex.getStrand() + ""; break; case 3: value = hitVertex.getGenomeAcc(); break; case 4: value = hitVertex.getOrganism(); break; default: break; } } else if (index < (5 + min)) { value = hitVertex.getTaxon().getTaxon(index - 5); } else { value = hitVertex.getAttribute((String) colorComboBox.getItemAt(index)); System.out.println(index + " " + "attr"); } if (!attrValues.contains(value)) { attrValues.add(value); } } } float hue = 0; int size = attrValues.size(); for (int i = 0; i < size; i++) { Color c = Color.getHSBColor(hue, 0.85f, 1.0f); colorMap.put(attrValues.get(i), c); hue += 1.0f / size; } if (index < (5 + min)) { rc.setVertexFillPaintTransformer(new VertexPainter(index, colorMap)); } else { rc.setVertexFillPaintTransformer(new AttrVertexPainter(attr, colorMap)); } vv.repaint(); } }; colorComboBox.addItemListener(colorItemListener); }