List of usage examples for java.util Set retainAll
boolean retainAll(Collection<?> c);
From source file:ca.uhn.fhir.jpa.dao.BaseFhirResourceDao.java
@Override public Set<Long> searchForIdsWithAndOr(SearchParameterMap theParams) { SearchParameterMap params = theParams; if (params == null) { params = new SearchParameterMap(); }/*from w ww .j a v a 2s .c o m*/ RuntimeResourceDefinition resourceDef = getContext().getResourceDefinition(myResourceType); Set<Long> pids = new HashSet<Long>(); for (Entry<String, List<List<? extends IQueryParameterType>>> nextParamEntry : params.entrySet()) { String nextParamName = nextParamEntry.getKey(); if (nextParamName.equals("_id")) { if (nextParamEntry.getValue().isEmpty()) { continue; } else if (nextParamEntry.getValue().size() > 1) { throw new InvalidRequestException( "AND queries not supported for _id (Multiple instances of this param found)"); } else { Set<Long> joinPids = new HashSet<Long>(); List<? extends IQueryParameterType> nextValue = nextParamEntry.getValue().get(0); if (nextValue == null || nextValue.size() == 0) { continue; } else { for (IQueryParameterType next : nextValue) { String value = next.getValueAsQueryToken(); IdDt valueId = new IdDt(value); try { long valueLong = translateForcedIdToPid(valueId); joinPids.add(valueLong); } catch (ResourceNotFoundException e) { // This isn't an error, just means no result found } } if (joinPids.isEmpty()) { continue; } } pids = addPredicateId(pids, joinPids); if (pids.isEmpty()) { return new HashSet<Long>(); } if (pids.isEmpty()) { pids.addAll(joinPids); } else { pids.retainAll(joinPids); } } } else if (nextParamName.equals("_language")) { pids = addPredicateLanguage(pids, nextParamEntry.getValue()); } else { RuntimeSearchParam nextParamDef = resourceDef.getSearchParam(nextParamName); if (nextParamDef != null) { switch (nextParamDef.getParamType()) { case DATE: for (List<? extends IQueryParameterType> nextAnd : nextParamEntry.getValue()) { pids = addPredicateDate(nextParamName, pids, nextAnd); if (pids.isEmpty()) { return new HashSet<Long>(); } } break; case QUANTITY: for (List<? extends IQueryParameterType> nextAnd : nextParamEntry.getValue()) { pids = addPredicateQuantity(nextParamName, pids, nextAnd); if (pids.isEmpty()) { return new HashSet<Long>(); } } break; case REFERENCE: for (List<? extends IQueryParameterType> nextAnd : nextParamEntry.getValue()) { pids = addPredicateReference(nextParamName, pids, nextAnd); if (pids.isEmpty()) { return new HashSet<Long>(); } } break; case STRING: for (List<? extends IQueryParameterType> nextAnd : nextParamEntry.getValue()) { pids = addPredicateString(nextParamName, pids, nextAnd); if (pids.isEmpty()) { return new HashSet<Long>(); } } break; case TOKEN: for (List<? extends IQueryParameterType> nextAnd : nextParamEntry.getValue()) { pids = addPredicateToken(nextParamName, pids, nextAnd); if (pids.isEmpty()) { return new HashSet<Long>(); } } break; case NUMBER: for (List<? extends IQueryParameterType> nextAnd : nextParamEntry.getValue()) { pids = addPredicateNumber(nextParamName, pids, nextAnd); if (pids.isEmpty()) { return new HashSet<Long>(); } } break; case COMPOSITE: for (List<? extends IQueryParameterType> nextAnd : nextParamEntry.getValue()) { pids = addPredicateComposite(nextParamDef, pids, nextAnd); if (pids.isEmpty()) { return new HashSet<Long>(); } } break; } } } } return pids; }
From source file:org.sakaiproject.content.tool.ListItem.java
/** * Set up the access roles as defined by checkboxes in the form. * Should only be called if it is compatible with the form submission * e.g. when access mode is not set to groups. *//*from w w w. j ava 2 s .c o m*/ protected void captureAccessRoles(ParameterParser params, String index) { Set<String> formRoleIds = new LinkedHashSet<String>(); String[] rolesArray = params.getStrings("access_roles" + index); if (rolesArray != null) { formRoleIds.addAll(Arrays.asList(rolesArray)); formRoleIds.retainAll(availableRoleIds()); } this.roleIds = formRoleIds; }
From source file:com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.java
/** * {@inheritDoc}/* w w w .j a va 2 s . c o m*/ */ @Override public Connections getConnectionsForCurrentUser(Set<ProfileField> profileFields) { assertNotNull("profile fields", profileFields); profileFields.retainAll(CONNECTION_FIELDS); LinkedInApiUrlBuilder builder = createLinkedInApiUrlBuilder( LinkedInApiUrls.GET_CONNECTIONS_FOR_CURRENT_USER); String apiUrl = builder.withFieldEnumSet(ParameterNames.FIELD_SELECTORS, profileFields).buildUrl(); return readResponse(Connections.class, callApiMethod(apiUrl)); }
From source file:com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.java
/** * {@inheritDoc}/*from w w w . j a v a 2s .co m*/ */ @Override public Connections getConnectionsById(String id, Set<ProfileField> profileFields) { assertNotNullOrEmpty("id", id); assertNotNull("profile fields", profileFields); profileFields.retainAll(CONNECTION_FIELDS); LinkedInApiUrlBuilder builder = createLinkedInApiUrlBuilder(LinkedInApiUrls.GET_CONNECTIONS_BY_ID); String apiUrl = builder.withField(ParameterNames.ID, id) .withFieldEnumSet(ParameterNames.FIELD_SELECTORS, profileFields).buildUrl(); return readResponse(Connections.class, callApiMethod(apiUrl)); }
From source file:com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.java
/** * {@inheritDoc}//ww w .j av a 2 s.co m */ @Override public Connections getConnectionsByUrl(String url, Set<ProfileField> profileFields) { assertNotNullOrEmpty("url", url); assertNotNull("profile fields", profileFields); profileFields.retainAll(CONNECTION_FIELDS); LinkedInApiUrlBuilder builder = createLinkedInApiUrlBuilder(LinkedInApiUrls.GET_CONNECTIONS_BY_URL); String apiUrl = builder.withField(ParameterNames.URL, url, true) .withFieldEnumSet(ParameterNames.FIELD_SELECTORS, profileFields).buildUrl(); return readResponse(Connections.class, callApiMethod(apiUrl)); }
From source file:gate.creole.ontology.impl.sesame.OntologyServiceImplSesame.java
/** * This method returns a set of all properties where the current resource has * been specified as one of the domain resources. Please note that this method * is different from the getAllSetProperties() method which returns a set of * properties set on the resource. For each property in the ontology, this * method checks if the current resource is valid domain. If so, the property * is said to be applicable, and otherwise not.. * // w w w .j av a 2 s .c o m * @param theResourceURI * @return */ public Property[] getPropertiesWithResourceAsDomain(String theResourceURI) { List<Property> list = new ArrayList<Property>(); HashSet<String> toCheck = new HashSet<String>(); try { if (repositoryConnection.hasStatement(string2SesameResource(theResourceURI), RDF.TYPE, OWL.CLASS, true // TODO: include inferred: true or false here? )) { String queryRep1 = string2Turtle(theResourceURI); String queryRep = "{" + queryRep1 + "}"; String query = "Select distinct SUPER FROM " + queryRep + " rdfs:subClassOf {SUPER}" + " WHERE SUPER!=" + queryRep1 + " AND SUPER != ALL ( " + " select distinct B FROM {B} owl:equivalentClass " + queryRep + ")"; addSerqlQueryResultToCollection(query, toCheck); toCheck.add(theResourceURI); } else if (repositoryConnection.hasStatement(string2SesameResource(theResourceURI), RDF.TYPE, RDF.PROPERTY, true)) { String queryRep1 = string2Turtle(theResourceURI); String queryRep = "{" + queryRep1 + "}"; String query = "Select distinct SUPER FROM " + queryRep + " rdfs:subPropertyOf {SUPER}" + " WHERE SUPER!=" + queryRep1 + " AND SUPER != ALL ( " + " select distinct B FROM {B} owl:equivalentProperty " + queryRep + ")"; addSerqlQueryResultToCollection(query, toCheck); toCheck.add(theResourceURI); } else { // it is an instance String queryRep1 = string2Turtle(theResourceURI); String query = "Select DISTINCT B from {X} rdf:type {B} WHERE X=" + queryRep1; addSerqlQueryResultToCollection(query, toCheck, true); } } catch (Exception e) { throw new GateOntologyException("Error getting statements", e); } String query = "Select distinct X FROM {X} rdf:type {<" + OWL.ANNOTATIONPROPERTY + ">}"; UtilTupleQueryIterator result = performSerqlQuery(query); while (result.hasNext()) { String anAnnProp = result.nextFirstAsString(); list.add(new Property(OConstants.ANNOTATION_PROPERTY, anAnnProp)); } result.close(); boolean allowSystemStatements = this.returnSystemStatements; this.returnSystemStatements = true; Property[] props = listToPropertyArray(list); this.returnSystemStatements = allowSystemStatements; // now we obtain all datatype properties list = new ArrayList<Property>(); query = "Select X FROM {X} rdf:type {<" + OWL.DATATYPEPROPERTY + ">}"; //iter = performQuery(query); result = performSerqlQuery(query); while (result.hasNext()) { String anAnnProp = result.nextFirstAsString(); // for each property we obtain its domain and search for the // resourceURI in it query = "select distinct Y from {<" + anAnnProp + ">} rdfs:domain {Y}"; Set<String> set = new HashSet<String>(); addSerqlQueryResultToCollection(query, set, true); if (set.isEmpty()) { list.add(new Property(OConstants.DATATYPE_PROPERTY, anAnnProp.toString())); } set = new HashSet<String>(reduceToMostSpecificClasses(set)); set.retainAll(toCheck); if (!set.isEmpty()) { list.add(new Property(OConstants.DATATYPE_PROPERTY, anAnnProp.toString())); } } result.close(); query = "Select X FROM {X} rdf:type {<" + OWL.OBJECTPROPERTY + ">}"; result = performSerqlQuery(query); while (result.hasNext()) { String anAnnProp = result.nextFirstAsString(); OURI annOURI = ontology.createOURI(anAnnProp); // for each property we obtain its domain and search for the // resourceURI in it query = "select distinct Y from {<" + anAnnProp + ">} rdfs:domain {Y}"; Set<String> set = new HashSet<String>(); addSerqlQueryResultToCollection(query, set, true); set = new HashSet<String>(reduceToMostSpecificClasses(set)); byte type = OConstants.OBJECT_PROPERTY; if (set.isEmpty()) { if (isSymmetricProperty(annOURI)) { type = OConstants.SYMMETRIC_PROPERTY; } else if (isTransitiveProperty(annOURI)) { type = OConstants.TRANSITIVE_PROPERTY; } list.add(new Property(type, anAnnProp)); continue; } set.retainAll(toCheck); if (!set.isEmpty()) { if (isSymmetricProperty(annOURI)) { type = OConstants.SYMMETRIC_PROPERTY; } else if (isTransitiveProperty(annOURI)) { type = OConstants.TRANSITIVE_PROPERTY; } list.add(new Property(type, anAnnProp)); } } result.close(); Property[] props1 = listToPropertyArray(list); Property[] toProps = new Property[props.length + props1.length]; for (int i = 0; i < props.length; i++) { toProps[i] = props[i]; } for (int i = 0; i < props1.length; i++) { toProps[props.length + i] = props1[i]; } return toProps; }
From source file:com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.java
/** * {@inheritDoc}/*from ww w. j a v a 2 s .com*/ */ @Override public Connections getConnectionsForCurrentUser(Set<ProfileField> profileFields, int start, int count) { assertPositiveNumber("start", start); assertPositiveNumber("count", count); assertNotNull("profile fields", profileFields); profileFields.retainAll(CONNECTION_FIELDS); LinkedInApiUrlBuilder builder = createLinkedInApiUrlBuilder( LinkedInApiUrls.GET_CONNECTIONS_FOR_CURRENT_USER); String apiUrl = builder.withFieldEnumSet(ParameterNames.FIELD_SELECTORS, profileFields) .withParameter(ParameterNames.START, String.valueOf(start)) .withParameter(ParameterNames.COUNT, String.valueOf(count)).buildUrl(); return readResponse(Connections.class, callApiMethod(apiUrl)); }
From source file:com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.java
/** * {@inheritDoc}/*from w w w .j a va2 s . c o m*/ */ @Override public Connections getConnectionsById(String id, Set<ProfileField> profileFields, int start, int count) { assertNotNullOrEmpty("id", id); assertPositiveNumber("start", start); assertPositiveNumber("count", count); assertNotNull("profile fields", profileFields); profileFields.retainAll(CONNECTION_FIELDS); LinkedInApiUrlBuilder builder = createLinkedInApiUrlBuilder(LinkedInApiUrls.GET_CONNECTIONS_BY_ID); String apiUrl = builder.withField(ParameterNames.ID, id) .withFieldEnumSet(ParameterNames.FIELD_SELECTORS, profileFields) .withParameter(ParameterNames.START, String.valueOf(start)) .withParameter(ParameterNames.COUNT, String.valueOf(count)).buildUrl(); return readResponse(Connections.class, callApiMethod(apiUrl)); }
From source file:com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.java
/** * {@inheritDoc}/* w w w. j a v a2 s.c o m*/ */ @Override public Connections getConnectionsByUrl(String url, Set<ProfileField> profileFields, int start, int count) { assertNotNullOrEmpty("url", url); assertPositiveNumber("start", start); assertPositiveNumber("count", count); assertNotNull("profile fields", profileFields); profileFields.retainAll(CONNECTION_FIELDS); LinkedInApiUrlBuilder builder = createLinkedInApiUrlBuilder(LinkedInApiUrls.GET_CONNECTIONS_BY_URL); String apiUrl = builder.withField(ParameterNames.URL, url, true) .withFieldEnumSet(ParameterNames.FIELD_SELECTORS, profileFields) .withParameter(ParameterNames.START, String.valueOf(start)) .withParameter(ParameterNames.COUNT, String.valueOf(count)).buildUrl(); return readResponse(Connections.class, callApiMethod(apiUrl)); }
From source file:com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.java
/** * {@inheritDoc}//from w w w . ja v a 2 s.co m */ @Override public Connections getConnectionsForCurrentUser(Set<ProfileField> profileFields, Date modificationDate, ConnectionModificationType modificationType) { assertNotNull("profile fields", profileFields); assertNotNull("modification date", modificationDate); assertNotNull("modification type", modificationType); profileFields.retainAll(CONNECTION_FIELDS); LinkedInApiUrlBuilder builder = createLinkedInApiUrlBuilder( LinkedInApiUrls.GET_CONNECTIONS_FOR_CURRENT_USER); String apiUrl = builder.withFieldEnumSet(ParameterNames.FIELD_SELECTORS, profileFields) .withParameter(ParameterNames.MODIFIED_SINCE, String.valueOf(modificationDate.getTime())) .withParameterEnum(ParameterNames.MODIFICATION, modificationType).buildUrl(); return readResponse(Connections.class, callApiMethod(apiUrl)); }