Java Code Examples for java.util.ArrayList#retainAll()
The following examples show how to use
java.util.ArrayList#retainAll() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TemplateKB.java From wings with Apache License 2.0 | 6 votes |
public Link getLink(Node fromN, Node toN, Port fromPort, Port toPort) { ArrayList<Link> links = new ArrayList<Link>(); if(fromN != null && nodeOutputLinks.containsKey(fromN.getID())) { links.addAll(this.nodeOutputLinks.get(fromN.getID())); if(toN != null && nodeInputLinks.containsKey(toN.getID())) links.retainAll(this.nodeInputLinks.get(toN.getID())); } else if(toN != null && nodeInputLinks.containsKey(toN.getID())) { links.addAll(this.nodeInputLinks.get(toN.getID())); } for(Link l : links) { boolean ok = true; if(l.getOriginPort() != null && fromPort != null && !l.getOriginPort().getID().equals(fromPort.getID())) ok = false; if(l.getDestinationPort() != null && toPort != null && !l.getDestinationPort().getID().equals(toPort.getID())) ok = false; if(ok) return l; } return null; }
Example 2
Source File: FedSumSourceSelection.java From CostFed with GNU Affero General Public License v3.0 | 6 votes |
/** * Remove irrelvant sources from each triple pattern according to step-2 of our source selection * @param stmtToLstAuthorities A map which stores the list of authorities for each capable source of a triple pattern * @param authIntersectionSet The common authorities set. see step 2 at FedSum paper for the usage of this list */ private void doSourcePrunning(Map<StatementPattern, Map<StatementSource, ArrayList<String>>> stmtToLstAuthorities,ArrayList<String> authIntersectionSet) { for(StatementPattern stmt:stmtToLstAuthorities.keySet()) { Map<StatementSource, ArrayList<String>> stmtSourceToLstAuthorities = stmtToLstAuthorities.get(stmt); for(StatementSource src:stmtSourceToLstAuthorities.keySet()) { ArrayList<String> srcAuthSet = stmtSourceToLstAuthorities.get(src); srcAuthSet.retainAll(authIntersectionSet); if(srcAuthSet.size()==0) { List<StatementSource> sources = stmtToSources.get(stmt); synchronized (sources) { sources.remove(src); } } } } }
Example 3
Source File: HibiscusSourceSelection.java From CostFed with GNU Affero General Public License v3.0 | 6 votes |
/** * Remove irrelvant sources from each triple pattern according to step-2 of our source selection * @param stmtToLstAuthorities A map which stores the list of authorities for each capable source of a triple pattern * @param authIntersectionSet The common authorities set. see step 2 at FedSum paper for the usage of this list */ private void doSourcePrunning(Map<StatementPattern, Map<StatementSource, ArrayList<String>>> stmtToLstAuthorities,ArrayList<String> authIntersectionSet) { for(StatementPattern stmt:stmtToLstAuthorities.keySet()) { Map<StatementSource, ArrayList<String>> stmtSourceToLstAuthorities = stmtToLstAuthorities.get(stmt); for(StatementSource src:stmtSourceToLstAuthorities.keySet()) { ArrayList<String> srcAuthSet = stmtSourceToLstAuthorities.get(src); srcAuthSet.retainAll(authIntersectionSet); if(srcAuthSet.size()==0) { List<StatementSource> sources = stmtToSources.get(stmt); synchronized (sources) { sources.remove(src); } } } } }
Example 4
Source File: ExpressionList.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override @Nullable public Class<?>[] acceptChange(final ChangeMode mode) { Class<?>[] l = expressions[0].acceptChange(mode); if (l == null) return null; final ArrayList<Class<?>> r = new ArrayList<>(Arrays.asList(l)); for (int i = 1; i < expressions.length; i++) { l = expressions[i].acceptChange(mode); if (l == null) return null; r.retainAll(Arrays.asList(l)); if (r.isEmpty()) return null; } return r.toArray(new Class[r.size()]); }
Example 5
Source File: FastArrayList.java From Penetration_Testing_POC with Apache License 2.0 | 6 votes |
/** * Remove from this collection all of its elements except those that are * contained in the specified collection. * * @param collection Collection containing elements to be retained * * @exception UnsupportedOperationException if this optional operation * is not supported by this list */ public boolean retainAll(Collection collection) { if (fast) { synchronized (this) { ArrayList temp = (ArrayList) list.clone(); boolean result = temp.retainAll(collection); list = temp; return (result); } } else { synchronized (list) { return (list.retainAll(collection)); } } }
Example 6
Source File: gen_mutual_friends_matrix.java From MLHadoop with Apache License 2.0 | 5 votes |
public TreeMap<String,ArrayList<String>> generate(TreeMap<String,ArrayList<String>> x){ for(Entry<String, ArrayList<String>> s1:x.entrySet()){ for(Entry<String, ArrayList<String>> s2:x.entrySet()){ if(!s1.getKey().contentEquals(s2.getKey()) && Integer.parseInt(s2.getKey())>Integer.parseInt(s1.getKey())){ ArrayList<String> mutual=s1.getValue(); mutual.retainAll(s2.getValue()); list.put(s1.getKey()+","+s2.getKey(), mutual); } } } return list; }
Example 7
Source File: ReadDirectoryTimerTask.java From mil-sym-java with Apache License 2.0 | 5 votes |
@Override public void run() { try { // retain old list of plugins ArrayList<String> oldList = new ArrayList<String>(); oldList.addAll(fileNames); // clear current list and rebuild clear(); File dirToRead = new File(this.directoryPath); File[] files = dirToRead.listFiles(); if (files != null) { for (File f : files) { fileNames.add(f.getName()); // System.out.printf("adding:\t%s\n", f.getAbsolutePath()); } } // compare original and updated list to see if there are differences. If so, reload the plugins. int oldSize = oldList.size(); oldList.retainAll(fileNames); if (oldSize != fileNames.size()) { // System.out.println("reloading plugins!"); ImagingUtils.reloadPlugins(); } } catch (Exception exception) { exception.printStackTrace(); } }
Example 8
Source File: CityParser.java From nadia with Apache License 2.0 | 5 votes |
@Override public ParseResults parse(String utterance) { ParseResults results=new ParseResults(utterance); utterance=utterance.replace('?', ' '); utterance=utterance.replace('!', ' '); utterance=utterance.replace(',', ' '); String decap_utterance=utterance.toLowerCase(); ArrayList<String> gazetteer = new ArrayList<String>(Arrays.asList("aberdeen","edinburgh", "glasgow","inverness", "portree", "uig", "malaig", "balloch","munich","berlin","hamburg","cologne","redmond")); ArrayList<String> tokens=new ArrayList<String>(Arrays.asList(decap_utterance.split(" ")));//tokenize tokens.retainAll(gazetteer); String value=""; if(tokens.size()>0){ for(String city : tokens){ String capitalizedCity = Character.toString(city.charAt(0)).toUpperCase()+city.substring(1); if(utterance.contains(city)){ value = city; } else{ //if capitalized value = capitalizedCity; } int index = utterance.indexOf(value); results.add(new ParseResult(this.name,index,index+value.length()-1,value,this.type,capitalizedCity)); } } return results; }
Example 9
Source File: PayloadTypeTest.java From Smack with Apache License 2.0 | 5 votes |
/** * Test for the difference of payloads when we are handling the same sets. */ public void testDifferenceSameSet() { ArrayList<Audio> set1 = new ArrayList<Audio>(); ArrayList<Audio> set2 = new ArrayList<Audio>(); PayloadType.Audio common1 = new PayloadType.Audio(34, "supercodec-1", 2, 14000); PayloadType.Audio common2 = new PayloadType.Audio(56, "supercodec-2", 1, 44000); PayloadType.Audio common3 = new PayloadType.Audio(0, "supercodec-3", 1, 44000); PayloadType.Audio common4 = new PayloadType.Audio(120, "supercodec-4", 2, 66060); set1.add(common1); set1.add(common2); set1.add(common3); set1.add(common4); set2.add(common1); set2.add(common2); set2.add(common3); set2.add(common4); // Get the difference ArrayList<Audio> commonSet = new ArrayList<Audio>(); commonSet.addAll(set1); commonSet.retainAll(set2); assertTrue(commonSet.size() == 4); assertTrue(commonSet.contains(common1)); assertTrue(commonSet.contains(common2)); }
Example 10
Source File: PayloadTypeTest.java From Smack with Apache License 2.0 | 5 votes |
/** * Test for the difference of payloads. */ public void testDifference() { ArrayList<Audio> set1 = new ArrayList<Audio>(); ArrayList<Audio> set2 = new ArrayList<Audio>(); PayloadType.Audio common1 = new PayloadType.Audio(34, "supercodec-1", 2, 14000); PayloadType.Audio common2 = new PayloadType.Audio(56, "supercodec-2", 1, 44000); set1.add(common1); set1.add(common2); set1.add(new PayloadType.Audio(36, "supercodec-3", 2, 28000)); set1.add(new PayloadType.Audio(45, "supercodec-4", 1, 98000)); set2.add(new PayloadType.Audio(27, "supercodec-3", 2, 28000)); set2.add(common2); set2.add(new PayloadType.Audio(32, "supercodec-4", 1, 98000)); set2.add(common1); // Get the difference ArrayList<Audio> commonSet = new ArrayList<Audio>(); commonSet.addAll(set1); commonSet.retainAll(set2); assertTrue(commonSet.size() == 2); System.out.println("Codec " + ((PayloadType.Audio)commonSet.get(0)).getId()); System.out.println("Codec " + ((PayloadType.Audio)commonSet.get(1)).getId()); assertTrue(commonSet.contains(common1)); assertTrue(commonSet.contains(common2)); }
Example 11
Source File: TLSSocketFactory.java From braintree_android with MIT License | 5 votes |
private Socket enableTLSOnSocket(Socket socket) { if (socket instanceof SSLSocket) { ArrayList<String> supportedProtocols = new ArrayList<>(Arrays.asList(((SSLSocket) socket).getSupportedProtocols())); supportedProtocols.retainAll(Collections.singletonList("TLSv1.2")); ((SSLSocket) socket).setEnabledProtocols(supportedProtocols.toArray(new String[supportedProtocols.size()])); } return socket; }
Example 12
Source File: AnnotatedElementFilterTest.java From revapi with Apache License 2.0 | 5 votes |
private <T> void assertNotContains(List<T> list, T... elements) { ArrayList<T> intersection = new ArrayList<>(list); intersection.retainAll(Arrays.asList(elements)); if (!intersection.isEmpty()) { Assert.fail("List " + list + " shouldn't have contained any of the " + Arrays.asList(elements)); } }
Example 13
Source File: SortedList.java From hbase with Apache License 2.0 | 5 votes |
@Override public synchronized boolean retainAll(Collection<?> c) { ArrayList<E> newList = new ArrayList<>(list); // Removals in ArrayList won't break sorting boolean changed = newList.retainAll(c); list = Collections.unmodifiableList(newList); return changed; }
Example 14
Source File: Collections9.java From JAADAS with GNU General Public License v3.0 | 5 votes |
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { String s1 = req.getParameter(FIELD_NAME); LinkedList c1 = new LinkedList(); c1.addLast(s1); ArrayList c2 = new ArrayList(); c2.add("abc"); c2.retainAll(c1); String s2 = (String) c2.get(0); PrintWriter writer = resp.getWriter(); writer.println(s2); /* OK */ }
Example 15
Source File: JoinTLink.java From twister2 with Apache License 2.0 | 5 votes |
/** * Uses a different build pattern than the usual {@link edu.iu.dsc.tws.api.tset.link.TLink}s * * @param graphBuilder graph builder * @param buildSequence build seq */ @Override public void build(GraphBuilder graphBuilder, Collection<? extends TBase> buildSequence) { // filter out the relevant sources out of the predecessors ArrayList<TBase> sources = new ArrayList<>(getTBaseGraph().getPredecessors(this)); sources.retainAll(buildSequence); if (sources.size() != 2) { throw new RuntimeException("Join TLink predecessor count should be 2: Received " + sources.size()); } // filter out the relevant sources out of the successors HashSet<TBase> targets = new HashSet<>(getTBaseGraph().getSuccessors(this)); targets.retainAll(buildSequence); MessageType kType = getSchema().getKeyType(); MessageType dTypeL = getSchema().getDataType(); MessageType dTypeR = getSchema().getDataTypeRight(); for (TBase target : targets) { // group name = left_right_join_target String groupName = leftTSet.getId() + "_" + rightTSet.getId() + "_" + getId() + "_" + target.getId(); // build left buildJoin(graphBuilder, leftTSet, target, 0, groupName, kType, dTypeL, getSchema().isLengthsSpecified(), getSchema().getKeySize(), getSchema().getTotalSize()); // build right buildJoin(graphBuilder, rightTSet, target, 1, groupName, kType, dTypeR, getSchema().isRightLengthsSpecified(), getSchema().getKeySize(), getSchema().getRightTotalSize()); } }
Example 16
Source File: AbstractDbTable.java From base-module with Apache License 2.0 | 5 votes |
/** * 拷贝 oldTable 表里的数据到 newTable * * @param db * @param oldTable * @param newTable */ static void copyTableData(SQLiteDatabase db, String oldTable, String newTable) { Log.d(TAG, "copyTableData(" + oldTable + ", " + newTable + ")..."); //先将新表数据清空 db.delete(newTable, null, null); //然后获取新旧表的列属性,查看旧表里哪些列属性被删除了 ArrayList<String> oldColumns = new ArrayList<String>(listColumns(db, oldTable)); List<String> newColumns = listColumns(db, newTable); oldColumns.retainAll(newColumns); //根据公共的列属性对旧表数据进行拷贝 String commonColumns = TextUtils.join(",", oldColumns); Log.d(TAG, "copyTableData: Common columns: " + commonColumns); db.execSQL(String.format(SQL_COPY_TABLE_DATA, newTable, commonColumns, commonColumns, oldTable)); }
Example 17
Source File: DanmakuThreadFactory.java From BakaDanmaku with MIT License | 5 votes |
/** * 重启所有线程 同样可以用于初始化时线程的启动 */ public static void restartThreads() { // 获得所有的 platforms String[] _platforms = BakaDanmakuConfig.livePlatform.platform.split(","); for (int i = 0; i < _platforms.length; i++) { _platforms[i] = _platforms[i].trim(); // 剔除行首行尾空格 } // 获得所有的平台 ArrayList<String> platforms = new ArrayList<>(Arrays.asList(_platforms)); // 获得正在运行的弹幕线程 ArrayList<String> running = getRunningDanmakuThread(); // 创建一个 restart 数据,存入刚刚正在运行的弹幕线程列表 ArrayList<String> restart = new ArrayList<>(running); // 获得两者的交集 restart.retainAll(platforms); // 创建一个 toStop 数据,存入刚刚正在运行的弹幕线程列表 ArrayList<String> toStop = new ArrayList<>(running); // 获得两者的差集 toStop.removeAll(platforms); // 创建一个 toStart 数据,存入所有的平台列表 ArrayList<String> toStart = new ArrayList<>(platforms); // 获得两者的差集 toStart.removeAll((getRunningDanmakuThread())); // restart 部分,依次进行停止、并重启 restart.forEach((platform) -> stopThread(platform, true)); // toStop 部分,依次进行停止 toStop.forEach(DanmakuThreadFactory::stopThread); // toStart 部分,依次进行开启 toStart.forEach(DanmakuThreadFactory::runThread); }
Example 18
Source File: DataMover.java From tuffylite with Apache License 2.0 | 4 votes |
public double calcLogPartitionFunction(ArrayList<GAtom> _tomargin, Set<Component> components){ double rs = -1; ArrayList<Partition> parts = new ArrayList<Partition>(); for(Component c : components){ parts.addAll(c.parts); } for(Partition p : parts){ ArrayList<GAtom> tomargin = new ArrayList<GAtom>(); for(Integer i : p.mrf.getCoreAtoms()){ tomargin.add(p.mrf.atoms.get(i)); } tomargin.retainAll(_tomargin); int[] cstate = new int[tomargin.size()]; for(int i=0;i<cstate.length;i++){ cstate[i] = 0; } cstate[0] = -1; UIMan.println(":-( I am going to margin 2^" + cstate.length + " worlds!"); Double metacost = null; while(true){ cstate[0] = cstate[0] + 1; boolean exitFlag = false; for(int i = 0; i < cstate.length; i++){ if(cstate[i] == 2){ cstate[i] = 0; if(i+1 != cstate.length){ cstate[i+1] ++; }else{ exitFlag = true; break; } }else{ break; } } if(exitFlag == true){ break; } for(Integer atom : p.mrf.getCoreAtoms()){ p.mrf.atoms.get(atom).truth = false; } BitSet conf = new BitSet(_tomargin.size()+1); for(int i = 0; i < cstate.length; i++){ if(cstate[i] == 0){ tomargin.get(i).truth = false; }else{ tomargin.get(i).truth = true; conf.set(tomargin.get(i).id); } } if(!wordLogPF.containsKey(p)){ wordLogPF.put(p, new LinkedHashMap<BitSet, Double>()); } wordLogPF.get(p).put(conf, -p.mrf.calcCosts()); if(metacost == null){ metacost = -p.mrf.calcCosts(); }else{ metacost = logAdd(metacost, -p.mrf.calcCosts()); } } partLogPF.put(p, metacost); if(rs==-1){ rs = metacost; }else{ rs = rs + metacost; } } wholeLogPF = rs; return rs; }
Example 19
Source File: WorkingSetAdapter.java From n4js with Eclipse Public License 1.0 | 4 votes |
@Override public IAdaptable[] adaptElements(final IAdaptable[] objects) { final ArrayList<IAdaptable> elements = newArrayList(getElements()); elements.retainAll(newArrayList(objects)); return Iterables.toArray(elements, IAdaptable.class); }