Example usage for java.util Set clear

List of usage examples for java.util Set clear

Introduction

In this page you can find the example usage for java.util Set clear.

Prototype

void clear();

Source Link

Document

Removes all of the elements from this set (optional operation).

Usage

From source file:org.apache.sling.scripting.sightly.impl.engine.extension.URIManipulationFilterExtension.java

private void replaceSelectors(Set<String> selectors, String[] selectorsArray) {
    selectors.clear();
    selectors.addAll(Arrays.asList(selectorsArray));
}

From source file:com.yqboots.security.core.UserManagerImpl.java

/**
 * {@inheritDoc}//from ww  w.j  a v  a  2  s.c  om
 */
@Override
@Transactional
@Auditable(code = SecurityAudit.CODE_UPDATE_ROLES_OF_USER)
public void updateRoles(final String username, final String... rolePaths) throws UserNotFoundException {
    Assert.hasText(username);

    final User user = userRepository.findByUsername(username);
    if (user == null) {
        throw new UserNotFoundException(username);
    }

    final Set<Role> userRoles = user.getRoles();
    if (CollectionUtils.isNotEmpty(userRoles)) {
        userRoles.clear();
    }

    if (ArrayUtils.isNotEmpty(rolePaths)) {
        final List<Role> roles = roleRepository.findByPathIn(Arrays.asList(rolePaths));
        if (!roles.isEmpty()) {
            user.setRoles(new HashSet<>(roles));
        }
    }
}

From source file:com.yqboots.security.core.UserManagerImpl.java

/**
 * {@inheritDoc}/*from   ww  w.j a v a 2s  .co m*/
 */
@Override
@Transactional
@Auditable(code = SecurityAudit.CODE_UPDATE_ROLES_OF_USER)
public void updateRoles(final String username, final Long... roleIds) throws UserNotFoundException {
    Assert.hasText(username);

    final User user = userRepository.findByUsername(username);
    if (user == null) {
        throw new UserNotFoundException(username);
    }

    final Set<Role> userRoles = user.getRoles();
    if (CollectionUtils.isNotEmpty(userRoles)) {
        userRoles.clear();
    }

    if (ArrayUtils.isNotEmpty(roleIds)) {
        final List<Role> roles = roleRepository.findAll(Arrays.asList(roleIds));
        if (!roles.isEmpty()) {
            user.setRoles(new HashSet<>(roles));
        }
    }
}

From source file:com.yqboots.security.core.UserManagerImpl.java

/**
 * {@inheritDoc}//from  w w w .  j  a  v  a 2  s .  c  o m
 */
@Override
@Transactional
@Auditable(code = SecurityAudit.CODE_UPDATE_GROUPS_OF_USER)
public void updateGroups(final String username, final Long... groupIds) throws UserNotFoundException {
    Assert.hasText(username);

    final User user = userRepository.findByUsername(username);
    if (user == null) {
        throw new UserNotFoundException(username);
    }

    final Set<Group> userGroups = user.getGroups();
    if (CollectionUtils.isNotEmpty(userGroups)) {
        userGroups.clear();
    }

    if (ArrayUtils.isNotEmpty(groupIds)) {
        final List<Group> groups = groupRepository.findAll(Arrays.asList(groupIds));
        if (!groups.isEmpty()) {
            user.setGroups(new HashSet<>(groups));
        }
    }
}

From source file:com.yqboots.security.core.UserManagerImpl.java

/**
 * {@inheritDoc}//from  ww  w.  ja  va  2  s. c o  m
 */
@Override
@Transactional
@Auditable(code = SecurityAudit.CODE_UPDATE_GROUPS_OF_USER)
public void updateGroups(final String username, final String... groupPaths) throws UserNotFoundException {
    Assert.hasText(username);

    final User user = userRepository.findByUsername(username);
    if (user == null) {
        throw new UserNotFoundException(username);
    }

    // if groupPaths is empty, will remove all
    final Set<Group> userGroups = user.getGroups();
    if (CollectionUtils.isNotEmpty(userGroups)) {
        userGroups.clear();
    }

    if (ArrayUtils.isNotEmpty(groupPaths)) {
        final List<Group> groups = groupRepository.findByPathIn(Arrays.asList(groupPaths));
        if (!groups.isEmpty()) {
            user.setGroups(new HashSet<>(groups));
        }
    }
}

From source file:edu.mayo.qdm.executor.drools.DroolsExecutor.java

public void doExecute(Iterable<Patient> patients, KnowledgeBase knowledgeBase,
        MeasurementPeriod measurementPeriod, Map<String, String> valueSetDefinitions, ResultCallback callback) {
    Set<Patient> cache = new HashSet<Patient>();
    for (Patient p : patients) {
        if (cache.size() < EXECUTION_BATCH_SIZE) {
            cache.add(p);/*from w  w w  . j a  v  a2  s. c  o m*/
        } else {
            this.doExecuteBatch(cache, knowledgeBase, measurementPeriod, valueSetDefinitions, callback);
            cache.clear();
            cache.add(p);
        }
    }

    if (cache.size() > 0) {
        this.doExecuteBatch(cache, knowledgeBase, measurementPeriod, valueSetDefinitions, callback);
    }
}

From source file:org.apache.hyracks.control.cc.executor.ActivityClusterPlanner.java

private Map<ActivityId, ActivityPlan> buildActivityPlanMap(ActivityCluster ac, JobRun jobRun,
        Map<ActivityId, ActivityPartitionDetails> pcMap) {
    Map<ActivityId, ActivityPlan> activityPlanMap = new HashMap<>();
    Set<ActivityId> depAnIds = new HashSet<>();
    for (ActivityId anId : ac.getActivityMap().keySet()) {
        depAnIds.clear();
        getDependencyActivityIds(depAnIds, anId, ac);
        ActivityPartitionDetails apd = pcMap.get(anId);
        Task[] tasks = new Task[apd.getPartitionCount()];
        ActivityPlan activityPlan = new ActivityPlan(apd);
        for (int i = 0; i < tasks.length; ++i) {
            TaskId tid = new TaskId(anId, i);
            tasks[i] = new Task(tid, activityPlan);
            for (ActivityId danId : depAnIds) {
                ActivityCluster dAC = ac.getActivityClusterGraph().getActivityMap().get(danId);
                ActivityClusterPlan dACP = jobRun.getActivityClusterPlanMap().get(dAC.getId());
                assert dACP != null : "IllegalStateEncountered: Dependent AC is being planned without a plan for "
                        + "dependency AC: Encountered no plan for ActivityID " + danId;
                Task[] dATasks = dACP.getActivityPlanMap().get(danId).getTasks();
                assert dATasks != null : "IllegalStateEncountered: Dependent AC is being planned without a plan for"
                        + " dependency AC: Encountered no plan for ActivityID " + danId;
                assert dATasks.length == tasks.length : "Dependency activity partitioned differently from "
                        + "dependent: " + dATasks.length + " != " + tasks.length;
                Task dTask = dATasks[i];
                TaskId dTaskId = dTask.getTaskId();
                tasks[i].getDependencies().add(dTaskId);
                dTask.getDependents().add(tid);
            }/* ww w. j  a v a  2s .c o  m*/
        }
        activityPlan.setTasks(tasks);
        activityPlanMap.put(anId, activityPlan);
    }
    return activityPlanMap;
}

From source file:eu.annocultor.tagger.postprocessors.PeopleTermFilter.java

@Override
public TermList disambiguate(TermList terms, DisambiguationContext disambiguationContext) throws Exception {

    // disambiguation not needed
    if (terms.size() < 2)
        return terms;

    TermList results = new TermList();

    if (!(disambiguationContext instanceof UlanDisambiguationContext))
        throw new Exception(
                "Expected ULAN-specific disambiguation context. Apperantly, Ulan.disambiguate was called outside Ulan lookupPerson.");

    UlanDisambiguationContext udc = (UlanDisambiguationContext) disambiguationContext;

    for (Term term : terms) {
        // ulan years
        Set<Integer> ulanBirthYears = years("birth", term);
        Set<Integer> ulanDeathYears = years("death", term);
        // 100 years was added to ULAN when no death date was there
        if (!ulanBirthYears.isEmpty() && !ulanDeathYears.isEmpty()
                && ulanBirthYears.iterator().next() + 100 == ulanDeathYears.iterator().next()) {
            ulanDeathYears.clear();
        }/*from  www  .  j  a  v a2  s. c  o  m*/
        // request years
        int reqBirthYear = 0;
        int reqDeathYear = 0;

        if (udc.birthDate != null) {
            if (udc.birthDate.matches("^\\d\\d\\d\\d(\\-(.+))?"))
                reqBirthYear = Integer.parseInt(udc.birthDate.substring(0, 4));
            if (reqBirthYear >= now.get(Calendar.YEAR)) {
                reqBirthYear = 0;
            }
        }
        if (udc.deathDate != null) {
            if (udc.deathDate.matches("^\\d\\d\\d\\d(\\-(.+))?"))
                reqDeathYear = Integer.parseInt(udc.deathDate.substring(0, 4));
            if (reqDeathYear >= now.get(Calendar.YEAR)) {
                reqDeathYear = 0;
            }
        }

        // comparing the ulan dates with the requested dates 
        if (udc.isLiveDate) {
            if (checkDates(ulanBirthYears, ulanDeathYears, reqBirthYear, reqDeathYear, 3, true))
            // reqBirthYear should be a year of ULAN life
            //            if (reqBirthYear >= Collections.min(ulanBirthYears) 
            //                  && (ulanDeathYears.isEmpty() || reqBirthYear <= Collections.max(ulanDeathYears)))
            {
                results.add(term);
                term.setDisambiguatingComment(
                        String.format("requested year of life %d matched ULAN lifetime (%s-%s)", reqBirthYear,
                                toString(ulanBirthYears), toString(ulanDeathYears)));
            }
        } else {
            // requested years should match ULAN years
            if (reqBirthYear == 0 && reqDeathYear == 0) {
                // no years
                results.add(term);
                term.setDisambiguatingComment("Matching name only, no life dates provided");
            } else {
                // check years
                if (checkDates(ulanBirthYears, ulanDeathYears, reqBirthYear, reqDeathYear, 3, false)) {
                    results.add(term);
                    term.setDisambiguatingComment(String.format(
                            "requested lifetime (%d-%d) matched ULAN lifetime (%s-%s)", reqBirthYear,
                            reqDeathYear, toString(ulanBirthYears), toString(ulanDeathYears)));
                }
            }

            // Unambiguous choice that fails date check 
            if (terms.size() == 1 && results.isEmpty()) {
                // do a very relaxed check
                //if (checkDates(ulanBirthYears, ulanDeathYears, reqBirthYear, reqDeathYear, 25, false))               
                {
                    results.add(term);
                    term.setConfidenceComment(String.format(
                            "requested lifetime (%d-%d) DID NOT really match ULAN lifetime (%s-%s)",
                            reqBirthYear, reqDeathYear, toString(ulanBirthYears), toString(ulanDeathYears)));
                    term.setDisambiguatingComment("Maching name, and relaxed match on life dates");
                }
            }

        }
    }
    return (results.size() == 1) ? results : new TermList();
}

From source file:io.gravitee.repository.redis.management.internal.impl.EventRedisRepositoryImpl.java

@Override
public Page<RedisEvent> search(EventCriteria filter, Pageable pageable) {
    Set<String> filterKeys = new HashSet<>();
    String tempDestination = "tmp-" + Math.abs(filter.hashCode());

    // Implement OR clause for event type
    if (!filter.getTypes().isEmpty()) {
        filter.getTypes().forEach(type -> filterKeys.add(REDIS_KEY + ":type:" + type));
        redisTemplate.opsForZSet().unionAndStore(null, filterKeys, tempDestination);
        filterKeys.clear();
        filterKeys.add(tempDestination);
    }// w ww  .ja  v  a2 s .c  o m

    // Add clause based on event properties
    Set<String> internalUnionFilter = new HashSet<>();
    filter.getProperties().forEach((propertyKey, propertyValue) -> {
        if (propertyValue instanceof Collection) {
            Set<String> collectionFilter = new HashSet<>(((Collection) propertyValue).size());
            String collectionTempDestination = "tmp-" + propertyKey + ":" + propertyValue.hashCode();
            ((Collection) propertyValue)
                    .forEach(value -> collectionFilter.add(REDIS_KEY + ":" + propertyKey + ":" + value));
            redisTemplate.opsForZSet().unionAndStore(null, collectionFilter, collectionTempDestination);
            internalUnionFilter.add(collectionTempDestination);
            filterKeys.add(collectionTempDestination);
        } else {
            filterKeys.add(REDIS_KEY + ":" + propertyKey + ":" + propertyValue);
        }
    });

    // And finally add clause based on event update date
    filterKeys.add(REDIS_KEY + ":updated_at");

    redisTemplate.opsForZSet().intersectAndStore(null, filterKeys, tempDestination);

    Set<Object> keys;

    if (filter.getFrom() != 0 && filter.getTo() != 0) {
        if (pageable != null) {
            keys = redisTemplate.opsForZSet().reverseRangeByScore(tempDestination, filter.getFrom(),
                    filter.getTo(), pageable.from(), pageable.pageSize());
        } else {
            keys = redisTemplate.opsForZSet().reverseRangeByScore(tempDestination, filter.getFrom(),
                    filter.getTo());
        }
    } else {
        if (pageable != null) {
            keys = redisTemplate.opsForZSet().reverseRangeByScore(tempDestination, 0, Long.MAX_VALUE,
                    pageable.from(), pageable.pageSize());
        } else {
            keys = redisTemplate.opsForZSet().reverseRangeByScore(tempDestination, 0, Long.MAX_VALUE);
        }
    }

    redisTemplate.opsForZSet().removeRange(tempDestination, 0, -1);
    internalUnionFilter.forEach(dest -> redisTemplate.opsForZSet().removeRange(dest, 0, -1));
    List<Object> eventObjects = redisTemplate.opsForHash().multiGet(REDIS_KEY, keys);

    return new Page<>(
            eventObjects.stream().map(event -> convert(event, RedisEvent.class)).collect(Collectors.toList()),
            (pageable != null) ? pageable.pageNumber() : 0, (pageable != null) ? pageable.pageSize() : 0,
            keys.size());
}

From source file:edu.uci.ics.hyracks.control.cc.scheduler.ActivityClusterPlanner.java

private Map<ActivityId, ActivityPlan> buildActivityPlanMap(ActivityCluster ac, JobRun jobRun,
        Map<ActivityId, ActivityPartitionDetails> pcMap) {
    Map<ActivityId, ActivityPlan> activityPlanMap = new HashMap<ActivityId, ActivityPlan>();
    Set<ActivityId> depAnIds = new HashSet<ActivityId>();
    for (ActivityId anId : ac.getActivityMap().keySet()) {
        depAnIds.clear();
        getDependencyActivityIds(depAnIds, anId, ac);
        ActivityPartitionDetails apd = pcMap.get(anId);
        Task[] tasks = new Task[apd.getPartitionCount()];
        ActivityPlan activityPlan = new ActivityPlan(apd);
        for (int i = 0; i < tasks.length; ++i) {
            TaskId tid = new TaskId(anId, i);
            tasks[i] = new Task(tid, activityPlan);
            for (ActivityId danId : depAnIds) {
                ActivityCluster dAC = ac.getActivityClusterGraph().getActivityMap().get(danId);
                ActivityClusterPlan dACP = jobRun.getActivityClusterPlanMap().get(dAC.getId());
                assert dACP != null : "IllegalStateEncountered: Dependent AC is being planned without a plan for dependency AC: Encountered no plan for ActivityID "
                        + danId;/*  w w  w.ja  v  a  2 s . com*/
                Task[] dATasks = dACP.getActivityPlanMap().get(danId).getTasks();
                assert dATasks != null : "IllegalStateEncountered: Dependent AC is being planned without a plan for dependency AC: Encountered no plan for ActivityID "
                        + danId;
                assert dATasks.length == tasks.length : "Dependency activity partitioned differently from dependent: "
                        + dATasks.length + " != " + tasks.length;
                Task dTask = dATasks[i];
                TaskId dTaskId = dTask.getTaskId();
                tasks[i].getDependencies().add(dTaskId);
                dTask.getDependents().add(tid);
            }
        }
        activityPlan.setTasks(tasks);
        activityPlanMap.put(anId, activityPlan);
    }
    return activityPlanMap;
}