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

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

源代码1 项目: JVoiceXML   文件: EventCountTypeFilter.java
/**
 * {@inheritDoc}
 */
@Override
public void filter(final Collection<EventStrategy> strategies,
        final JVoiceXMLEvent event, final CatchContainer item) {
    final int size = strategies.size();
    final Collection<EventStrategy> matchingStrategies =
        new java.util.ArrayList<EventStrategy>();

    for (EventStrategy strategy : strategies) {
        final String type = strategy.getEventType();
        if (item instanceof EventCountable) {
            final EventCountable countable = (EventCountable) item;
            final int count = countable.getEventCount(type);
            if (count >= strategy.getCount()) {
                matchingStrategies.add(strategy);
            }
        }
    }
    strategies.retainAll(matchingStrategies);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("reducing event strategies by count from "
                + size + " to " + matchingStrategies.size());
    }

}
 
源代码2 项目: org.openntf.domino   文件: Document.java
@Override
public boolean isEditable() {
	boolean result = false;
	int access = getAncestorDatabase().getCurrentAccessLevel();
	if (access > 3) {
		//			System.out.println("isEditable is true because current user " + getAncestorSession().getEffectiveUserName()
		//					+ " has access level " + access);
		return true;	//editor, designer or manager
	}
	if (access < 3) {
		//			System.out.println("isEditable is false because current user " + getAncestorSession().getEffectiveUserName()
		//					+ " has access level " + access);
		return false;	//no access (impossible), depositor or reader
	}
	//author
	Name name = getAncestorSession().getEffectiveUserNameObject();
	String serverName = getAncestorDatabase().getServer();
	Collection<String> names = name.getGroups(serverName);
	names.retainAll(getAuthors());
	if (!names.isEmpty()) {
		result = true;
	}
	return result;
}
 
@Override
public Collection<VisualNode> collect(VisualModel model) {
    Collection<VisualNode> contacts = new HashSet<>();
    if (model instanceof VisualCircuit) {
        VisualCircuit circuit = (VisualCircuit) model;
        contacts.addAll(Hierarchy.getDescendantsOfType(circuit.getRoot(), VisualFunctionContact.class));
        Collection<Node> selection = new LinkedList<>(circuit.getSelection());
        for (Node node: new LinkedList<>(selection)) {
            if (node instanceof VisualFunctionComponent) {
                VisualFunctionComponent component = (VisualFunctionComponent) node;
                selection.addAll(component.getVisualOutputs());
            }
        }
        contacts.retainAll(selection);
    }
    return contacts;
}
 
源代码4 项目: pcgen   文件: CompoundAndPrimitive.java
@Override
public <R> Collection<? extends R> getCollection(PlayerCharacter pc, Converter<T, R> c)
{
	Collection<? extends R> returnSet = null;
	for (PrimitiveCollection<T> cs : primCollection)
	{
		if (returnSet == null)
		{
			returnSet = cs.getCollection(pc, c);
		}
		else
		{
			returnSet.retainAll(cs.getCollection(pc, c));
		}
	}
	return returnSet;
}
 
@Override
public Collection<VisualNode> collect(VisualModel model) {
    Collection<VisualNode> components = new HashSet<>();
    components.addAll(Hierarchy.getDescendantsOfType(model.getRoot(), VisualCircuitComponent.class));
    components.retainAll(model.getSelection());
    return components;
}
 
源代码6 项目: sharding-jdbc-1.5.1   文件: ShardingRule.java
/**
 * 过滤出所有的Binding表名称.
 * 
 * @param logicTables 逻辑表名称集合
 * @return 所有的Binding表名称集合
 */
public Collection<String> filterAllBindingTables(final Collection<String> logicTables) {
    if (logicTables.isEmpty()) {
        return Collections.emptyList();
    }
    Optional<BindingTableRule> bindingTableRule = findBindingTableRule(logicTables);
    if (!bindingTableRule.isPresent()) {
        return Collections.emptyList();
    }
    Collection<String> result = new ArrayList<>(bindingTableRule.get().getAllLogicTables());
    result.retainAll(logicTables);
    return result;
}
 
源代码7 项目: codebase   文件: FlowNode.java
@Override
public Collection<IDataNode> getReadWriteDocuments() {
	Collection<IDataNode> result = new ArrayList<IDataNode>();
	result.addAll(this.readDocuments);
	result.retainAll(this.writeDocuments);
	return result;
}
 
源代码8 项目: secure-data-service   文件: UserResource.java
static Response validateAtMostOneAdminRole(final Collection<String> roles) {
    Collection<String> adminRoles = new ArrayList<String>(Arrays.asList(ADMIN_ROLES));
    adminRoles.retainAll(roles);
    if (adminRoles.size() > 1) {
        return composeForbiddenResponse("You cannot assign more than one admin role to a user");
    }
    return null;
}
 
源代码9 项目: roboconf-platform   文件: FromGraphDefinition.java
private void checkNameCollisions() {

		Collection<String> names = new HashSet<> ();
		names.addAll( this.componentNameToComponentData.keySet());
		names.retainAll( this.facetNameToFacetData.keySet());

		for( String name : names ) {
			ComponentData cd = this.componentNameToComponentData.get( name );
			this.errors.addAll( cd.error( ErrorCode.CO_CONFLICTING_NAME, name( name )));

			FacetData fd = this.facetNameToFacetData.get( name );
			this.errors.addAll( fd.error( ErrorCode.CO_CONFLICTING_NAME, name( name )));
		}
	}
 
@Override
public Collection<VisualNode> collect(VisualModel model) {
    Collection<VisualNode> places = new HashSet<>();
    if (model instanceof VisualStg) {
        VisualStg stg = (VisualStg) model;
        places.addAll(stg.getVisualPlaces());
        Collection<VisualNode> selection = stg.getSelection();
        if (!selection.isEmpty()) {
            places.retainAll(selection);
        }
    }
    return places;
}
 
源代码11 项目: Conversations   文件: CryptoHelper.java
public static String[] getOrderedCipherSuites(final String[] platformSupportedCipherSuites) {
    final Collection<String> cipherSuites = new LinkedHashSet<>(Arrays.asList(Config.ENABLED_CIPHERS));
    final List<String> platformCiphers = Arrays.asList(platformSupportedCipherSuites);
    cipherSuites.retainAll(platformCiphers);
    cipherSuites.addAll(platformCiphers);
    filterWeakCipherSuites(cipherSuites);
    cipherSuites.remove("TLS_FALLBACK_SCSV");
    return cipherSuites.toArray(new String[cipherSuites.size()]);
}
 
源代码12 项目: onedev   文件: RoleMultiChoiceEditor.java
@Override
protected void onInitialize() {
	super.onInitialize();
	
	Map<String, String> roleNames = new LinkedHashMap<>();
	for (Role role: OneDev.getInstance(RoleManager.class).query())
		roleNames.put(role.getName(), role.getName());
	
	Collection<String> selections = new ArrayList<>();
	if (getModelObject() != null)
		selections.addAll(getModelObject());
	
	selections.retainAll(roleNames.keySet());
	
	input = new StringMultiChoice("input", Model.of(selections), Model.ofMap(roleNames)) {

		@Override
		protected void onInitialize() {
			super.onInitialize();
			getSettings().configurePlaceholder(descriptor);
		}
		
	};
       input.setConvertEmptyInputStringToNull(true);
       
       input.setRequired(descriptor.isPropertyRequired());
       input.setLabel(Model.of(getDescriptor().getDisplayName()));
       
	input.add(new AjaxFormComponentUpdatingBehavior("change"){

		@Override
		protected void onUpdate(AjaxRequestTarget target) {
			onPropertyUpdating(target);
		}
		
	});
	
       add(input);
}
 
@Override
public Collection<VisualNode> collect(VisualModel model) {
    Collection<VisualNode> connections = new HashSet<>();
    connections.addAll(Hierarchy.getDescendantsOfType(model.getRoot(), VisualConnection.class));
    Collection<? extends VisualNode> selection = model.getSelection();
    if (!selection.isEmpty()) {
        HashSet<Node> selectedConnections = new HashSet<>(selection);
        selectedConnections.retainAll(connections);
        if (!selectedConnections.isEmpty()) {
            connections.retainAll(selection);
        }
    }
    return connections;
}
 
@Override
public Collection<VisualNode> collect(VisualModel model) {
    Collection<VisualNode> signalTransitions = new HashSet<>();
    if (model instanceof VisualStg) {
        VisualStg stg = (VisualStg) model;
        signalTransitions.addAll(stg.getVisualSignalTransitions());
        signalTransitions.retainAll(stg.getSelection());
    }
    return signalTransitions;
}
 
源代码15 项目: netbeans   文件: CollectionUtils.java
public static <A,B> A[] retainAll(A[] a, B[] b) {
    if (a.length == 0) {
        return a;
    }
    if (b.length == 0) {
        return makeArray(a, 0);
    }
    Collection<A> setA = new HashSet<A>(Arrays.asList(a));
    Collection<B> setB = new HashSet<B>(Arrays.asList(b));
    setA.retainAll(setB);
    return setA.isEmpty() ? makeArray(a, 0)
                          : setA.toArray(makeArray(a, setA.size()));
}
 
@Override
public Collection<VisualNode> collect(VisualModel model) {
    Collection<VisualNode> signalTransitions = new HashSet<>();
    if (model instanceof VisualStg) {
        VisualStg stg = (VisualStg) model;
        signalTransitions.addAll(stg.getVisualSignalTransitions());
        Collection<VisualNode> selection = stg.getSelection();
        if (!selection.isEmpty()) {
            signalTransitions.retainAll(selection);
        }
    }
    return signalTransitions;
}
 
private Collection<String> getIntersectionDataSources() {
    Collection<String> result = new HashSet<>();
    for (RouteResult each : routeResults) {
        if (result.isEmpty()) {
            result.addAll(each.getActualDataSourceNames());
        }
        result.retainAll(each.getActualDataSourceNames());
    }
    return result;
}
 
源代码18 项目: javacore   文件: CollectionDemo.java
public static void main(String[] args) {
    Collection<String> c = new ArrayList<String>();
    c.addAll(Countries.names(6));
    c.add("ten");
    c.add("eleven");
    System.out.println(c);
    // Make an array from the List:
    Object[] array = c.toArray();
    // Make a String array from the List:
    String[] str = c.toArray(new String[0]);
    // Find max and min elements; this means
    // different things depending on the way
    // the Comparable interface is implemented:
    System.out.println("Collections.max(c) = " + Collections.max(c));
    System.out.println("Collections.min(c) = " + Collections.min(c));
    // Add a Collection to another Collection
    Collection<String> c2 = new ArrayList<String>();
    c2.addAll(Countries.names(6));
    c.addAll(c2);
    System.out.println(c);
    c.remove(Countries.DATA[0][0]);
    System.out.println(c);
    c.remove(Countries.DATA[1][0]);
    System.out.println(c);
    // Remove all components that are
    // in the argument collection:
    c.removeAll(c2);
    System.out.println(c);
    c.addAll(c2);
    System.out.println(c);
    // Is an element in this Collection?
    String val = Countries.DATA[3][0];
    System.out.println("c.contains(" + val + ") = " + c.contains(val));
    // Is a Collection in this Collection?
    System.out.println("c.containsAll(c2) = " + c.containsAll(c2));
    Collection<String> c3 = ((List<String>) c).subList(3, 5);
    // Keep all the elements that are in both
    // c2 and c3 (an intersection of sets):
    c2.retainAll(c3);
    System.out.println(c2);
    // Throw away all the elements
    // in c2 that also appear in c3:
    c2.removeAll(c3);
    System.out.println("c2.isEmpty() = " + c2.isEmpty());
    c = new ArrayList<String>();
    c.addAll(Countries.names(6));
    System.out.println(c);
    c.clear(); // Remove all elements
    System.out.println("after c.clear():" + c);
}
 
源代码19 项目: depan   文件: GraphModel.java
public Collection<GraphNode> and(GraphModel that) {
  Collection<GraphNode> result = Sets.newHashSet(getNodesSet());
  result.retainAll(that.getNodes());

  return result;
}
 
源代码20 项目: mage-android   文件: PeopleCursorAdapter.java
@Override
public void bindView(View v, final Context context, Cursor cursor) {
	try {
		Location location = query.mapRow(new AndroidDatabaseResults(cursor, null, false));
		User user = location.getUser();
		if (user == null) {
			return;
		}

		ImageView avatarView = v.findViewById(R.id.avatarImageView);
		Drawable defaultPersonIcon = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_person_white_24dp));
		DrawableCompat.setTint(defaultPersonIcon, ContextCompat.getColor(context, R.color.icon));
		DrawableCompat.setTintMode(defaultPersonIcon, PorterDuff.Mode.SRC_ATOP);
		avatarView.setImageDrawable(defaultPersonIcon);

		GlideApp.with(context)
				.load(Avatar.Companion.forUser(user))
				.fallback(defaultPersonIcon)
				.error(defaultPersonIcon)
				.circleCrop()
				.into(avatarView);

		final ImageView iconView = v.findViewById(R.id.iconImageView);
		GlideApp.with(context)
				.load(user.getUserLocal().getLocalIconPath())
				.centerCrop()
				.into(iconView);

		TextView name = v.findViewById(R.id.name);
		name.setText(user.getDisplayName());

		TextView date = v.findViewById(R.id.date);
		String timeText = new PrettyTime().format(location.getTimestamp());
		date.setText(timeText);

		Collection<Team> userTeams = teamHelper.getTeamsByUser(user);
		userTeams.retainAll(eventTeams);
		Collection<String> teamNames = Collections2.transform(userTeams, new Function<Team, String>() {
			@Override
			public String apply(Team team) {
				return team.getName();
			}
		});

		TextView teamsView = v.findViewById(R.id.teams);
		teamsView.setText(StringUtils.join(teamNames, ", "));

	} catch (SQLException sqle) {
		Log.e(LOG_NAME, "Could not set location view information.", sqle);
	}
}