List of usage examples for java.util Set clear
void clear();
From source file:gov.nih.nci.firebird.service.account.AccountConfigurationHelper.java
private void refreshProfiles(Set<InvestigatorProfile> profiles) { Set<InvestigatorProfile> profilesToRefresh = Sets.newHashSet(profiles); profiles.clear(); for (InvestigatorProfile profile : profilesToRefresh) { profiles.add(getRefreshedProfile(profile)); }/*from w w w . jav a 2 s .c o m*/ }
From source file:gov.nih.nci.firebird.service.account.AccountConfigurationHelper.java
private void refreshOrganizations(Set<Organization> organizations) { Set<Organization> organizationsToRefresh = Sets.newHashSet(organizations); organizations.clear(); for (Organization organization : organizationsToRefresh) { organizations.add(getRefreshedOrganization(organization)); }// ww w . j a v a 2 s . co m }
From source file:org.broadleafcommerce.openadmin.server.security.service.AdminUserProvisioningServiceImpl.java
@Override public AdminUserDetails provisionAdminUser(BroadleafExternalAuthenticationUserDetails details) { HashSet<String> newRoles = new HashSet<String>(); if (roleNameSubstitutions != null && !roleNameSubstitutions.isEmpty()) { for (GrantedAuthority authority : details.getAuthorities()) { if (roleNameSubstitutions.containsKey(authority.getAuthority())) { String[] roles = roleNameSubstitutions.get(authority.getAuthority()); for (String role : roles) { newRoles.add(role.trim()); }/*from www . j a va 2 s . c o m*/ } else { newRoles.add(authority.getAuthority()); } } } else { for (GrantedAuthority authority : details.getAuthorities()) { newRoles.add(authority.getAuthority()); } } HashSet<GrantedAuthority> newAuthorities = new HashSet<GrantedAuthority>(); for (String perm : AdminSecurityService.DEFAULT_PERMISSIONS) { newAuthorities.add(new SimpleGrantedAuthority(perm)); } HashSet<AdminRole> grantedRoles = new HashSet<AdminRole>(); List<AdminRole> adminRoles = securityService.readAllAdminRoles(); if (adminRoles != null) { for (AdminRole role : adminRoles) { if (newRoles.contains(role.getName())) { grantedRoles.add(role); Set<AdminPermission> permissions = role.getAllPermissions(); if (permissions != null && !permissions.isEmpty()) { for (AdminPermission permission : permissions) { if (permission.isFriendly()) { for (AdminPermission childPermission : permission.getAllChildPermissions()) { newAuthorities.add(new SimpleGrantedAuthority(childPermission.getName())); } } else { newAuthorities.add(new SimpleGrantedAuthority(permission.getName())); } } } } } } AdminUser adminUser = securityService.readAdminUserByUserName(details.getUsername()); if (adminUser == null) { adminUser = new AdminUserImpl(); adminUser.setLogin(details.getUsername()); } if (StringUtils.isNotBlank(details.getEmail())) { adminUser.setEmail(details.getEmail()); } StringBuilder name = new StringBuilder(); if (StringUtils.isNotBlank(details.getFirstName())) { name.append(details.getFirstName()).append(" "); } if (StringUtils.isNotBlank(details.getLastName())) { name.append(details.getLastName()); } String fullName = name.toString(); if (StringUtils.isNotBlank(fullName)) { adminUser.setName(fullName); } else { adminUser.setName(details.getUsername()); } //We have to do this because BLC replies on the role relationships being stored in the DB Set<AdminRole> roleSet = adminUser.getAllRoles(); //First, remove all roles associated with the user if they already existed if (roleSet != null) { //First, remove all role relationships in case they have changed roleSet.clear(); } else { roleSet = new HashSet<AdminRole>(); adminUser.setAllRoles(roleSet); } //Now, add all of the role relationships back. if (adminRoles != null) { for (AdminRole role : adminRoles) { roleSet.add(role); } } //Add optional support for things like Multi-Tenant, etc... adminExternalLoginExtensionManager.getProxy().performAdditionalAuthenticationTasks(adminUser, details); //Save the user data and all of the roles... adminUser = securityService.saveAdminUser(adminUser); return new AdminUserDetails(adminUser.getId(), details.getUsername(), "", true, true, true, true, newAuthorities); }
From source file:com.kugou.opentsdb.OpenTsdb.java
/** * send a set of metrics to opentsdb/*from w ww .j av a 2 s. c o m*/ * * @param metrics */ public void send(Collection<OpenTsdbMetric> metrics) { // we set the patch size because of existing issue in opentsdb where large batch of metrics failed // see at https://groups.google.com/forum/#!topic/opentsdb/U-0ak_v8qu0 // we recommend batch size of 5 - 10 will be safer // alternatively you can enable chunked request if (null == metrics || metrics.isEmpty()) { return; } if (batchSizeLimit > 0 && metrics.size() > batchSizeLimit) { final Set<OpenTsdbMetric> smallMetrics = new HashSet<OpenTsdbMetric>(); for (final OpenTsdbMetric metric : metrics) { smallMetrics.add(metric); if (smallMetrics.size() >= batchSizeLimit) { sendHelper(smallMetrics); smallMetrics.clear(); } } sendHelper(smallMetrics); } else { sendHelper(metrics); } }
From source file:com.yqboots.security.core.GroupManagerImpl.java
/** * {@inheritDoc}//from ww w . java 2 s. com */ @Override @Transactional @Auditable(code = SecurityAudit.CODE_UPDATE_ROLES_OF_GROUP) public void updateRoles(final String path, final Long... roleIds) throws GroupNotFoundException { Assert.hasText(path); final Group group = groupRepository.findByPath(path); if (group == null) { throw new GroupNotFoundException(path); } final Set<Role> groupRoles = group.getRoles(); if (CollectionUtils.isNotEmpty(groupRoles)) { groupRoles.clear(); } if (ArrayUtils.isNotEmpty(roleIds)) { final List<Role> roles = roleRepository.findAll(Arrays.asList(roleIds)); if (!roles.isEmpty()) { group.setRoles(new HashSet<>(roles)); } } }
From source file:com.yqboots.security.core.GroupManagerImpl.java
/** * {@inheritDoc}/*from ww w. j ava 2s. c om*/ */ @Override @Transactional @Auditable(code = SecurityAudit.CODE_UPDATE_ROLES_OF_GROUP) public void updateRoles(final String path, final String... rolePaths) throws GroupNotFoundException { Assert.hasText(path); final Group group = groupRepository.findByPath(path); if (group == null) { throw new GroupNotFoundException(path); } final Set<Role> groupRoles = group.getRoles(); if (CollectionUtils.isNotEmpty(groupRoles)) { groupRoles.clear(); } if (ArrayUtils.isNotEmpty(rolePaths)) { final List<Role> roles = roleRepository.findByPathIn(Arrays.asList(rolePaths)); if (!roles.isEmpty()) { group.setRoles(new HashSet<>(roles)); } } }
From source file:com.liferay.jenkins.tools.JenkinsStatus.java
protected Collection<Build> getMatchingBuilds(Collection<Build> builds, Collection<BuildMatcher> buildMatchers) throws Exception { Collection<Build> startingBuilds = new HashSet<>(builds); Set<Build> matchingBuilds = new HashSet<>(); for (BuildMatcher buildMatcher : buildMatchers) { matchingBuilds.clear(); for (Build build : startingBuilds) { if (buildMatcher.matches(build)) { matchingBuilds.add(build); }/*from w ww . j a va2 s . co m*/ } startingBuilds = new HashSet<>(matchingBuilds); logger.debug("{} builds matches {}", matchingBuilds.size(), buildMatcher.getClass().getName()); } return matchingBuilds; }
From source file:com.redhat.persistence.oql.Query.java
public Code generate(Root root, boolean oracle) { Generator gen = (Generator) s_generators.get(); gen.init(root);//from ww w.j a v a2 s . co m m_query.hash(gen); for (int i = 0; i < m_names.size(); i++) { String name = (String) m_names.get(i); gen.hash(name); Expression e = get(name); e.hash(gen); } Code cached; synchronized (s_cache) { cached = (Code) s_cache.get(gen.getLookupKey()); } if (cached != null) { Code c = cached.resolve(gen.getBindings(), root); return c; } m_query.frame(gen); QFrame qframe = gen.getFrame(m_query); gen.push(qframe); try { for (int i = 0; i < m_names.size(); i++) { Expression e = get((String) m_names.get(i)); e.frame(gen); } } finally { gen.pop(); } if (s_log.isDebugEnabled()) { s_log.debug("unoptimized frame:\n" + qframe); } List frames = gen.getFrames(); boolean modified; do { modified = false; for (int i = 0; i < frames.size(); i++) { QFrame qf = (QFrame) frames.get(i); modified |= qf.hoist(); } } while (modified); if (s_log.isDebugEnabled()) { s_log.debug("hoisted frame:\n" + qframe); } for (int i = 0; i < frames.size(); i++) { QFrame qf = (QFrame) frames.get(i); qf.mergeOuter(); } if (s_log.isDebugEnabled()) { s_log.debug("outers merged:\n" + qframe); } for (int i = 0; i < frames.size(); i++) { QFrame qf = (QFrame) frames.get(i); if (qf.getParent() == null) { qf.equifill(); } } if (s_log.isDebugEnabled()) { s_log.debug("eq/nn filled:\n" + qframe); } Set collapse = new HashSet(); Map canon = new HashMap(); do { collapse.clear(); canon.clear(); modified = false; for (int i = 0; i < frames.size(); i++) { QFrame qf = (QFrame) frames.get(i); long st = System.currentTimeMillis(); modified |= qf.innerize(collapse, canon); } if (modified) { for (Iterator it = collapse.iterator(); it.hasNext();) { EquiSet eq = (EquiSet) it.next(); eq.collapse(); } } } while (modified); if (s_log.isDebugEnabled()) { s_log.debug("innerized frame:\n" + qframe); } for (Iterator it = gen.getFrames().iterator(); it.hasNext();) { QFrame qf = (QFrame) it.next(); qf.shrink(); } if (s_log.isDebugEnabled()) { s_log.debug("shrunk frame:\n" + qframe); } Code sql = new Code("select "); for (Iterator it = m_names.iterator(); it.hasNext();) { String name = (String) it.next(); Expression e = get(name); // XXX: should eliminate duplicate fetches here when // we return something smarter than a string from this // method. sql = sql.add(e.emit(gen)).add(" as \"").add(name).add("\""); if (it.hasNext()) { sql = sql.add(",\n "); } } if (m_names.isEmpty()) { sql = sql.add("1 as dummy"); } sql = sql.add("\nfrom ").add(qframe.emit(false, !oracle)); Expression offset = qframe.getOffset(); Expression limit = qframe.getLimit(); if (oracle && (offset != null || limit != null)) { // We need one level of nesting here to make sure that the // order by happens before the rownum assignments. The // second level of nesting is required because filtering // on rownum directly doesn't work. sql = new Code("select * from (select r__.*, rownum as ").add(ROWNUM).add(" from (").add(sql) .add(") r__) where "); if (offset != null) { sql = sql.add(ROWNUM).add(" > ").add(offset.emit(gen)); } if (limit != null) { if (offset != null) { sql = sql.add(" and "); } sql = sql.add(ROWNUM); if (offset != null) { sql = sql.add(" - ").add(offset.emit(gen)); } sql = sql.add(" <= ").add(limit.emit(gen)); } } // XXX: need better way to do size if (m_query instanceof Size) { sql = new Code("select count(*) as \"size\" from (").add(sql).add(") count__"); } synchronized (s_cache) { if (s_log.isInfoEnabled()) { s_log.info("Query cache MISS. Cache size " + s_cache.size()); if (s_log.isDebugEnabled()) { StringBuffer buf = new StringBuffer(); buf.append("Cache Key: ").append(gen.getStoreKey().toString()); buf.append("\nValue: ").append(sql); buf.append("\nQuery: ").append(toString()); s_log.debug(buf.toString()); } } s_cache.put(gen.getStoreKey(), sql); } sql = sql.resolve(gen.getBindings(), root); return sql; }
From source file:org.axiom_tools.storage.Surrogated.java
private <ComponentType extends SurrogatedItem> void saveComponents(Set<ComponentType> components) throws Exception { HashSet<ComponentType> results = new HashSet<>(components); for (ComponentType component : components) { results.add((ComponentType) component.saveItem()); }//from w w w . ja v a 2 s .c o m components.clear(); components.addAll(results); }
From source file:gov.nih.nci.cabig.ctms.acegi.acls.dao.impl.MutableAclDaoImpl.java
void deleteEntries(ObjectIdentity objectIdentity) { AclObjectIdentityBean oidBean = findAclObjectIdentityBeanByObjectIdentity(objectIdentity); Set aceBeans = oidBean.getAclEntries(); if (aceBeans.size() > 0) { aceBeans.clear(); // oidBean.setAclEntries(new HashSet()); getHibernateTemplate().deleteAll(aceBeans); getHibernateTemplate().update(oidBean); for (Iterator i = aceBeans.iterator(); i.hasNext();) { AclEntryBean entryBean = (AclEntryBean) i.next(); AclSidBean sidBean = entryBean.getSid(); if (sidBean != null) { sidBean.getAccessControlEntries().remove(entryBean); getHibernateTemplate().update(sidBean); }//from w w w .j ava 2 s. co m } } }