Example usage for java.util Set isEmpty

List of usage examples for java.util Set isEmpty

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this set contains no elements.

Usage

From source file:se.uu.it.cs.recsys.constraint.builder.CreditDomainBuilder.java

/**
 *
 * @param idSet//from ww  w  . j ava 2s  .  co m
 * @return the mapping between credit and the constraint set domain for the
 * input courses ids from planned years
 */
public Map<CourseCredit, SetDomain> getCreditAndIdSetDomainMappingFor(Set<Integer> idSet) {
    if (idSet == null || idSet.isEmpty()) {
        LOGGER.warn("Does not make sense to put null or empty set, right?");
        return Collections.EMPTY_MAP;
    }

    Map<CourseCredit, SetDomain> creditAndDomain = new HashMap<>();

    Map<CourseCredit, Set<Integer>> levelAndIds = getCreditAndIdSetMappingFor(idSet);

    levelAndIds.entrySet().stream().forEach((entry) -> {
        creditAndDomain.put(entry.getKey(), DomainBuilder.createDomain(entry.getValue()));
    });

    return creditAndDomain;
}

From source file:se.uu.it.cs.recsys.service.preference.SameCourseFinder.java

/**
 * Gets the info about course id collection representing the same course.
 * E.g a course with code "1DL301" can be planned in year 2015 and 2016 and
 * it will have different ids in DB in this case.
 *
 * @param scheduleInfo the info regarding which years are planned, e.g 2015;
 * non-empty input.//from  w  ww  . ja  va  2  s. c o  m
 * @return non-null collection regarding id set for same course.
 * @throws IllegalArgumentException if input is null or empty
 */
public Set<Set<Integer>> getIdCollectionForSameCourse(Set<CourseSchedule> scheduleInfo) {

    if (scheduleInfo == null || scheduleInfo.isEmpty()) {
        throw new IllegalArgumentException("Schedule input must be non-empty");
    }

    List<Course> allCourses = this.courseRepository.findAll();

    // find the first plan year, e.g 2015
    int firstPlanYear = scheduleInfo.stream().sorted(
            (schedule1, schedule2) -> Short.compare(schedule1.getTaughtYear(), schedule2.getTaughtYear()))
            .findFirst().get().getTaughtYear();

    // only get the course ids for plan year, e.g 2015, 2016
    Set<Course> planYearCourseSet = allCourses.stream()
            .filter(course -> course.getTaughtYear() >= firstPlanYear).collect(Collectors.toSet());

    Map<String, Set<Integer>> codeToIdSet = CourseFlattener.flattenToCodeAndIdSet(planYearCourseSet);

    Set<Set<Integer>> idCollectionForSameCourse = new HashSet<>();

    codeToIdSet.entrySet().stream().filter(entry -> entry.getValue().size() > 1).forEach(entry -> {
        idCollectionForSameCourse.add(entry.getValue());
    });

    return idCollectionForSameCourse;
}

From source file:edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.MaskingOntModelCache.java

private void checkForMissingNamedModels() {
    Set<String> missingModelNames = new HashSet<>(this.maskingNames);
    missingModelNames.removeAll(maskingCache.getModelNames());
    if (!missingModelNames.isEmpty()) {
        log.warn("Specifed models do not exist in the masking cache: " + missingModelNames);
        maskingNames.removeAll(missingModelNames);
    }//from   w  ww  . ja v a  2  s.  co m
}

From source file:net.camelpe.extension.camel.spi.CdiRegistry.java

/**
 * @see org.apache.camel.spi.Registry#lookup(java.lang.String)
 *//*from  ww  w .j a v a 2 s.co m*/
@Override
public Object lookup(final String name) {
    Validate.notEmpty(name, "name");
    getLog().trace("Looking up bean using name = [{}] in CDI registry ...", name);

    final Set<Bean<?>> beans = getDelegate().getBeans(name);
    if (beans.isEmpty()) {
        getLog().debug("Found no bean matching name = [{}] in CDI registry.", name);
        return null;
    }
    if (beans.size() > 1) {
        throw new IllegalStateException(
                "Expected to find exactly one bean having name [" + name + "], but got [" + beans.size() + "]");
    }
    final Bean<?> bean = beans.iterator().next();
    getLog().debug("Found bean [{}] matching name = [{}] in CDI registry.", bean, name);

    final CreationalContext<?> creationalContext = getDelegate().createCreationalContext(null);

    return getDelegate().getReference(bean, bean.getBeanClass(), creationalContext);
}

From source file:com.github.jmnarloch.spring.jaxrs.client.support.JaxRsClientClassPathScanner.java

/**
 * {@inheritDoc}//from ww  w  .j av a2 s. c o  m
 */
@Override
protected Set<BeanDefinitionHolder> doScan(String... basePackages) {

    final Set<BeanDefinitionHolder> beanDefinitions = super.doScan(basePackages);

    if (!beanDefinitions.isEmpty()) {
        processBeanDefinitions(beanDefinitions);
    }

    return beanDefinitions;
}

From source file:org.apache.niolex.config.ctrl.LoginController.java

@RequestMapping(method = RequestMethod.POST)
public @ResponseBody Map<String, ? extends Object> create(@ModelAttribute LoginInfo info,
        HttpServletRequest req) {//ww w.  j  a va 2s.  c  om
    Set<ConstraintViolation<LoginInfo>> failures = validator.validate(info);
    if (!failures.isEmpty()) {
        return Collections.singletonMap("msg", failures.iterator().next().getMessage());
    } else {
        CenterConnector updater = null;
        try {
            updater = new CenterConnector(serverAddress);
            String res = updater.subscribeAuthInfo(info.getUsername(), info.getPassword());
            if (!res.startsWith("SUCC")) {
                updater.stop();
                return Collections.singletonMap("msg", "???");
            } else {
                // Attach the updater to session.
                HttpSession sess = req.getSession();
                sess.setAttribute("login_cli", updater);
                // Auth success.
                return Collections.singletonMap("msg", "SUCCESS");
            }
        } catch (Exception e) {
            LOG.error("Error occured when connect to config center.", e);
            if (updater != null) {
                updater.stop();
            }
            return Collections.singletonMap("msg", "?");
        }
    }
}

From source file:com.github.fge.jsonschema.keyword.validator.draftv3.PropertiesValidator.java

@Override
public void validate(final Processor<FullData, FullData> processor, final ProcessingReport report,
        final MessageBundle bundle, final FullData data) throws ProcessingException {
    final Set<String> set = Sets.newLinkedHashSet(required);
    set.removeAll(Sets.newHashSet(data.getInstance().getNode().fieldNames()));

    if (!set.isEmpty())
        report.error(newMsg(data, bundle, "err.common.object.missingMembers").put("required", required)
                .putArgument("missing", toArrayNode(set)));
}

From source file:net.camelpe.extension.camel.spi.CdiRegistry.java

/**
 * @see org.apache.camel.spi.Registry#lookupByType(java.lang.Class)
 *///from w  ww  .  jav  a 2  s.  c om
@Override
public <T> Map<String, T> lookupByType(final Class<T> type) {
    Validate.notNull(type, "type");
    getLog().trace("Looking up all beans having expected type = [{}] in CDI registry ...", type.getName());

    final Set<Bean<?>> beans = getDelegate().getBeans(type);
    if (beans.isEmpty()) {
        getLog().debug("Found no beans having expected type = [{}] in CDI registry.", type.getName());

        return Collections.emptyMap();
    }
    getLog().debug("Found [{}] beans having expected type = [{}] in CDI registry.",
            Integer.valueOf(beans.size()), type.getName());

    final Map<String, T> beansByName = new HashMap<String, T>(beans.size());
    final CreationalContext<?> creationalContext = getDelegate().createCreationalContext(null);
    for (final Bean<?> bean : beans) {
        beansByName.put(bean.getName(), type.cast(getDelegate().getReference(bean, type, creationalContext)));
    }

    return beansByName;
}

From source file:com.github.rinde.rinsim.core.model.pdp.RandomVehicle.java

@Override
protected void tickImpl(TimeLapse time) {
    if (!time.hasTimeLeft()) {
        return;/*from w w w.j  a v a  2s.  com*/
    }
    if (!target.isPresent()) {
        target = findTarget();
    }

    if (target.isPresent()) {
        if (pm.get().containerContains(this, target.get())) {
            if (rm.get().getPosition(this).equals(target.get().getDeliveryLocation())) {
                pm.get().deliver(this, target.get(), time);
            } else {
                rm.get().moveTo(this, target.get().getDeliveryLocation(), time);
            }
        } else {
            if (pm.get().getParcelState(target.get()) != ParcelState.AVAILABLE) {
                // somebody got there first
                target = Optional.absent();
            } else if (rm.get().equalPosition(this, target.get())) {
                pm.get().pickup(this, target.get(), time);
            } else {
                rm.get().moveTo(this, target.get(), time);
            }
        }
    } else {
        final Set<Depot> depots = rm.get().getObjectsOfType(Depot.class);
        if (!depots.isEmpty()) {
            rm.get().moveTo(this, depots.iterator().next(), time);
        }
    }
}

From source file:com.google.api.tools.framework.importers.swagger.TopLevelBuilder.java

private void setServiceName(Service.Builder serviceBuilder, List<SwaggerFile> swaggerFiles, String defaultName)
        throws SwaggerConversionException {
    String serviceName = defaultName; // Try explicitly provided service name first.
    if (Strings.isNullOrEmpty(serviceName)) {
        Set<String> uniqueSwaggerHostNames = getSwaggerHosts(swaggerFiles);
        if (uniqueSwaggerHostNames.isEmpty()) {
            throw new SwaggerConversionException(
                    "Service name must be provided either explicitly or in Swagger 'host' value.");
        } else if (uniqueSwaggerHostNames.size() > 1) {
            throw new SwaggerConversionException(String.format(
                    "Different 'host' values cannot be set in multiple Swagger files, " + "found Hosts: {%s}",
                    Joiner.on(", ").join(uniqueSwaggerHostNames)));
        } else {/*from   www. ja v a2s.  c  o m*/
            serviceName = Iterables.getOnlyElement(uniqueSwaggerHostNames);
        }
    }
    serviceBuilder.setName(serviceName);
}