Example usage for java.util Collection isEmpty

List of usage examples for java.util Collection isEmpty

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this collection contains no elements.

Usage

From source file:com.thinkbiganalytics.jobrepo.query.model.transform.JobModelTransform.java

public static List<ExecutedJob> executedJobs(Collection<? extends BatchJobExecution> jobs) {
    if (jobs != null && !jobs.isEmpty()) {
        return jobs.stream().map(jobExecution -> executedJob(jobExecution)).collect(Collectors.toList());
    } else {/*  w w w  . ja v a  2  s  . c om*/
        return Collections.emptyList();
    }
}

From source file:com.thinkbiganalytics.jobrepo.query.model.transform.JobModelTransform.java

public static List<ExecutedJob> executedJobsSimple(Collection<? extends BatchJobExecution> jobs) {
    if (jobs != null && !jobs.isEmpty()) {
        return jobs.stream().map(jobExecution -> executedJobSimple(jobExecution)).collect(Collectors.toList());
    } else {//  w ww. ja  va2  s.c o  m
        return Collections.emptyList();
    }
}

From source file:org.ambraproject.wombat.controller.WombatController.java

/**
 * If any validation errors from a form are present, set them up to be rendered.
 * <p>/* w  w  w .j a v a2s .  c  o  m*/
 * If this method returns {@code true}, it generally means that the calling controller should halt and render a page
 * displaying the validation messages.
 *
 * @param response             the response
 * @param model                the model
 * @param validationErrorNames attribute names for present validation errors
 * @return {@code true} if a validation error is present
 */
protected static boolean applyValidation(HttpServletResponse response, Model model,
        Collection<String> validationErrorNames) {
    if (validationErrorNames.isEmpty())
        return false;

    /*
     * Presently, it is assumed that all validation error messages in FreeMarker use a simple presence/absence check
     * with the '??' operator. The value 'true' is just a placeholder. If any validation error messages require more
     * specific values, they must be added to the model separately. Refactor this method if that happens too often.
     */
    validationErrorNames.forEach(error -> model.addAttribute(error, true));

    response.setStatus(HttpStatus.BAD_REQUEST.value());
    return true;
}

From source file:com.thinkbiganalytics.jobrepo.query.model.transform.JobModelTransform.java

public static List<ExecutedStep> executedSteps(Collection<? extends BatchStepExecution> steps) {
    if (steps != null && !steps.isEmpty()) {
        return steps.stream().map(stepExecution -> executedStep(stepExecution)).collect(Collectors.toList());
    } else {//from   www.  java  2s .  co m
        return Collections.emptyList();
    }
}

From source file:grails.plugin.searchable.internal.util.GrailsDomainClassUtils.java

/**
 * Get the actual (user-defined) Classes for the given GrailsDomainClass Collection.
 * Equivalent to collecting the results of <code>grailsDomainClass.getClazz()</code> on
 * each element/* ww w .  j a  v  a  2s . c  o  m*/
 *
 * @param grailsDomainClasses
 * @return A collection of User-defined classes, which may be empty
 */
public static Collection getClazzes(Collection grailsDomainClasses) {
    if (grailsDomainClasses == null || grailsDomainClasses.isEmpty()) {
        return Collections.EMPTY_SET;
    }
    Set clazzes = new HashSet();
    for (Iterator iter = grailsDomainClasses.iterator(); iter.hasNext();) {
        clazzes.add(((GrailsDomainClass) iter.next()).getClazz());
    }
    return clazzes;
}

From source file:com.eviware.soapui.plugins.PluginProxies.java

@SuppressWarnings("unchecked")
static <T> T createProxyFor(T delegate) {

    if (delegate instanceof JComponent) {
        log.warn("Can't proxy JComponent derived classes");
        return delegate;
    }//from ww w .j a  v  a2 s .  co  m

    Collection<Class> interfaces = ClassUtils.getAllInterfaces(delegate.getClass());
    if (interfaces.isEmpty()) {
        // this shouldn't really happen, unless reflection is being used in some odd way
        log.warn("Can't proxy instance of {} because the class doesn't implement any interfaces",
                delegate.getClass());
        return delegate;
    }
    interfaces.add(PluginProxy.class);
    return (T) Proxy.newProxyInstance(PluginProxies.class.getClassLoader(),
            interfaces.toArray(new Class[interfaces.size()]), new DelegatingHandler<T>(delegate));
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.teacher.DeleteProfessorshipWithPerson.java

@Atomic
public static Boolean run(Person person, ExecutionCourse executionCourse) throws NotAuthorizedException {
    try {//  ww w . jav a 2s .co m

        final Person loggedPerson = AccessControl.getPerson();

        Professorship selectedProfessorship = null;
        selectedProfessorship = person.getProfessorshipByExecutionCourse(executionCourse);

        if ((loggedPerson == null) || (selectedProfessorship == null) || !loggedPerson.hasRole(RoleType.TEACHER)
                || isSamePersonAsBeingRemoved(loggedPerson, selectedProfessorship.getPerson())
                || selectedProfessorship.getResponsibleFor()) {
            throw new NotAuthorizedException();
        }
    } catch (RuntimeException e) {
        throw new NotAuthorizedException();
    }

    Professorship professorshipToDelete = person.getProfessorshipByExecutionCourse(executionCourse);

    Collection shiftProfessorshipList = professorshipToDelete.getAssociatedShiftProfessorshipSet();

    boolean hasCredits = false;

    if (!shiftProfessorshipList.isEmpty()) {
        hasCredits = CollectionUtils.exists(shiftProfessorshipList, new Predicate() {

            @Override
            public boolean evaluate(Object arg0) {
                ShiftProfessorship shiftProfessorship = (ShiftProfessorship) arg0;
                return shiftProfessorship.getPercentage() != null && shiftProfessorship.getPercentage() != 0;
            }
        });
    }

    if (!hasCredits && professorshipToDelete.getStudentInquiriesTeachingResultsSet().isEmpty()) {
        professorshipToDelete.delete();
    } else {
        if (hasCredits) {
            throw new DomainException("error.remove.professorship");
        }
    }
    return Boolean.TRUE;
}

From source file:gaffer.accumulo.utils.IngestUtils.java

/**
 * Get the existing splits from a table in Accumulo and write a splits file.
 * The number of splits is returned.//from  w w w.  ja  va 2  s . co  m
 * 
 * @param conn  An existing connection to an Accumulo instance
 * @param table  The table name
 * @param fs  The FileSystem in which to create the splits file
 * @param splitsFile  A path for the splits file
 * @return The number of splits in the table
 * @throws TableNotFoundException
 * @throws IOException
 */
public static int createSplitsFile(Connector conn, String table, FileSystem fs, Path splitsFile)
        throws TableNotFoundException, IOException {
    // Get the splits from the table
    Collection<Text> splits = conn.tableOperations().getSplits(table);

    // Write the splits to file
    if (splits.isEmpty()) {
        return 0;
    }
    PrintStream out = new PrintStream(new BufferedOutputStream(fs.create(splitsFile, true)));
    for (Text split : splits) {
        out.println(new String(Base64.encodeBase64(split.getBytes())));
    }
    out.close();

    return splits.size();
}

From source file:com.hengyi.japp.execution.Util.java

public static void queryCommand(CriteriaBuilder cb, CriteriaQuery<?> cq, Root<Task> root,
        TaskQueryCommand command) {/*w w  w .j av a  2  s.com*/
    Predicate p1 = cb.equal(root.get(Task_.charger), command.getOperator());
    ListJoin<Task, Operator> joinFollowers = root.join(Task_.followers, JoinType.LEFT);
    Predicate p2 = cb.equal(joinFollowers.get(Operator_.id), command.getOperator().getId());
    ListJoin<Task, Operator> joinExecutors = root.join(Task_.executors, JoinType.LEFT);
    Predicate p3 = cb.equal(joinExecutors.get(Operator_.id), command.getOperator().getId());
    Predicate p = cb.or(p1, p2, p3);
    if (command.getExecutor() != null) {
        p = cb.and(p, cb.equal(p, cb.isMember(command.getExecutor(), root.get(Task_.executors))));
    }
    if (command.getCustomer() != null) {
        p = cb.and(p, cb.equal(root.get(Task_.customer), command.getCustomer()));
    }
    if (!isBlank(command.getContent())) {
        p = cb.and(p, cb.like(root.get(Task_.content), command.getContentQuery()));
    }
    Collection<TaskType> TaskTypes = command.getTypes();
    if (TaskTypes != null && !TaskTypes.isEmpty()) {
        p = cb.and(p, root.get(Task_.type).in(TaskTypes));
    }
    Collection<TaskStatus> statuses = command.getStatuses();
    if (statuses != null && !statuses.isEmpty()) {
        p = cb.and(p, root.get(Task_.status).in(statuses));
    }
    if (command.getCreateDate() != null) {
        Date createDateStart = LocalDate.fromDateFields(command.getCreateDate()).toDate();
        Date createDateEnd = LocalDate.fromDateFields(command.getCreateDate()).plusDays(1).toDate();
        p = cb.and(p, cb.between(root.get(Task_.logInfo).get(LogInfo_.createDateTime), createDateStart,
                createDateEnd));
        // TODO timestamp date convert
        //p = cb.and(p, cb.equal(root.get(Task_.logInfo).get(LogInfo_.createDateTime).as(java.sql.Date.class), command.getCreateDate()));
    }
    cq.where(p);
}

From source file:net.landora.video.utils.UIUtils.java

public static Collection<Object> createCompleteContext(Collection<?> context) {
    if (context == null || context.isEmpty()) {
        return Collections.EMPTY_SET;
    }/*from  www.  j  ava2 s . c  om*/

    Collection<Object> result = new LinkedHashSet<Object>();
    for (Object obj : context) {
        addContentObject(obj, result);
    }
    return result;
}