Java Code Examples for java.util.Collection#retainAll()

The following examples show how to use java.util.Collection#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: CompoundAndPrimitive.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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;
}
 
Example 2
Source File: ToggleBubbleTransformationCommand.java    From workcraft with MIT License 6 votes vote down vote up
@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;
}
 
Example 3
Source File: Document.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 4
Source File: EventCountTypeFilter.java    From JVoiceXML with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * {@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());
    }

}
 
Example 5
Source File: ExpandHandshakeTransformationCommand.java    From workcraft with MIT License 5 votes vote down vote up
@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;
}
 
Example 6
Source File: ShardingCartesianRoutingEngine.java    From shardingsphere with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: MirrorTransitionTransformationCommand.java    From workcraft with MIT License 5 votes vote down vote up
@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;
}
 
Example 8
Source File: CollectionUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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()));
}
 
Example 9
Source File: ContractComponentTransformationCommand.java    From workcraft with MIT License 5 votes vote down vote up
@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;
}
 
Example 10
Source File: StraightenConnectionTransformationCommand.java    From workcraft with MIT License 5 votes vote down vote up
@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;
}
 
Example 11
Source File: RoleMultiChoiceEditor.java    From onedev with MIT License 5 votes vote down vote up
@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);
}
 
Example 12
Source File: CryptoHelper.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
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()]);
}
 
Example 13
Source File: ImplicitPlaceTransformationCommand.java    From workcraft with MIT License 5 votes vote down vote up
@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;
}
 
Example 14
Source File: FromGraphDefinition.java    From roboconf-platform with Apache License 2.0 5 votes vote down vote up
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 )));
		}
	}
 
Example 15
Source File: UserResource.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 16
Source File: FlowNode.java    From codebase with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Collection<IDataNode> getReadWriteDocuments() {
	Collection<IDataNode> result = new ArrayList<IDataNode>();
	result.addAll(this.readDocuments);
	result.retainAll(this.writeDocuments);
	return result;
}
 
Example 17
Source File: ShardingRule.java    From sharding-jdbc-1.5.1 with Apache License 2.0 5 votes vote down vote up
/**
 * 过滤出所有的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;
}
 
Example 18
Source File: CollectionDemo.java    From javacore with Creative Commons Attribution Share Alike 4.0 International 4 votes vote down vote up
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);
}
 
Example 19
Source File: GraphModel.java    From depan with Apache License 2.0 4 votes vote down vote up
public Collection<GraphNode> and(GraphModel that) {
  Collection<GraphNode> result = Sets.newHashSet(getNodesSet());
  result.retainAll(that.getNodes());

  return result;
}
 
Example 20
Source File: PeopleCursorAdapter.java    From mage-android with Apache License 2.0 4 votes vote down vote up
@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);
	}
}