java.util.ArrayList#retainAll ( )源码实例Demo

下面列出了java.util.ArrayList#retainAll ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Penetration_Testing_POC   文件: FastArrayList.java
/**
 * 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));
        }
    }

}
 
源代码2 项目: CostFed   文件: FedSumSourceSelection.java
/**
* 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);
				}
			}
		}
	}
	
}
 
源代码3 项目: CostFed   文件: HibiscusSourceSelection.java
/**
* 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);
				}
			}
		}
	}
	
}
 
源代码4 项目: Skript   文件: ExpressionList.java
@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()]);
}
 
源代码5 项目: wings   文件: TemplateKB.java
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;
}
 
源代码6 项目: BakaDanmaku   文件: DanmakuThreadFactory.java
/**
 * 重启所有线程 同样可以用于初始化时线程的启动
 */
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);
}
 
源代码7 项目: base-module   文件: AbstractDbTable.java
/**
 * 拷贝 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));
}
 
源代码8 项目: twister2   文件: JoinTLink.java
/**
 * 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());
  }
}
 
源代码9 项目: JAADAS   文件: Collections9.java
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 */
}
 
源代码10 项目: MLHadoop   文件: gen_mutual_friends_matrix.java
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;
}
 
源代码11 项目: hbase   文件: SortedList.java
@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;
}
 
源代码12 项目: revapi   文件: AnnotatedElementFilterTest.java
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));
    }
}
 
源代码13 项目: braintree_android   文件: TLSSocketFactory.java
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;
}
 
源代码14 项目: Smack   文件: PayloadTypeTest.java
/**
 * 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));
}
 
源代码15 项目: Smack   文件: PayloadTypeTest.java
/**
 * 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));
}
 
源代码16 项目: nadia   文件: CityParser.java
@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;
}
 
源代码17 项目: mil-sym-java   文件: ReadDirectoryTimerTask.java
@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();
	}
}
 
源代码18 项目: n4js   文件: WorkingSetAdapter.java
@Override
public IAdaptable[] adaptElements(final IAdaptable[] objects) {
	final ArrayList<IAdaptable> elements = newArrayList(getElements());
	elements.retainAll(newArrayList(objects));
	return Iterables.toArray(elements, IAdaptable.class);
}
 
源代码19 项目: tuffylite   文件: DataMover.java
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;

	}