Java Code Examples for org.apache.commons.collections.CollectionUtils#select()

The following examples show how to use org.apache.commons.collections.CollectionUtils#select() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventReportQueueJob.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static List<EventReportQueueJob> retrieveDoneGeneratedReports() {
    List<EventReportQueueJob> reports = new ArrayList<>();

    CollectionUtils.select(Bennu.getInstance().getQueueJobSet(), new Predicate() {

        @Override
        public boolean evaluate(Object arg0) {
            if (!(arg0 instanceof EventReportQueueJob)) {
                return false;
            }

            EventReportQueueJob eventReportQueueJob = (EventReportQueueJob) arg0;

            return eventReportQueueJob.getDone();
        }

    }, reports);

    return reports;
}
 
Example 2
Source File: ApprovedLearningAgreementDocumentFile.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected List<ApprovedLearningAgreementExecutedAction> getViewedLearningAgreementActions() {
    List<ApprovedLearningAgreementExecutedAction> executedActionList =
            new ArrayList<ApprovedLearningAgreementExecutedAction>();

    CollectionUtils.select(getExecutedActionsSet(), new Predicate() {

        @Override
        public boolean evaluate(Object arg0) {
            return ((ApprovedLearningAgreementExecutedAction) arg0).isViewedLearningAgreementAction();
        };

    }, executedActionList);

    Collections.sort(executedActionList, Collections.reverseOrder(ExecutedAction.WHEN_OCCURED_COMPARATOR));

    return executedActionList;
}
 
Example 3
Source File: CurricularCourse.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public boolean hasActiveScopeInGivenSemesterForCommonAndGivenBranch(final Integer semester, final Branch branch) {

    Collection<CurricularCourseScope> scopes = getScopesSet();

    List<CurricularCourseScope> result = (List<CurricularCourseScope>) CollectionUtils.select(scopes, new Predicate() {
        @Override
        public boolean evaluate(Object obj) {
            CurricularCourseScope curricularCourseScope = (CurricularCourseScope) obj;
            return ((curricularCourseScope.getBranch().getBranchType().equals(BranchType.COMNBR) || curricularCourseScope
                    .getBranch().equals(branch))
                    && curricularCourseScope.getCurricularSemester().getSemester().equals(semester) && curricularCourseScope
                    .isActive().booleanValue());
        }
    });

    return !result.isEmpty();
}
 
Example 4
Source File: CompetenceCourse.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public List<CurricularCourse> getCurricularCoursesWithActiveScopesInExecutionPeriod(final ExecutionSemester executionSemester) {
    return (List<CurricularCourse>) CollectionUtils.select(getAssociatedCurricularCoursesSet(), new Predicate() {

        @Override
        public boolean evaluate(Object arg0) {
            CurricularCourse curricularCourse = (CurricularCourse) arg0;

            for (DegreeModuleScope moduleScope : curricularCourse.getDegreeModuleScopes()) {
                if (moduleScope.isActiveForExecutionPeriod(executionSemester)) {
                    return true;
                }
            }
            return false;
        }
    });
}
 
Example 5
Source File: ErasmusCandidacyProcessDA.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected List<IndividualCandidacyProcess> getChildProcesses(final CandidacyProcess process, HttpServletRequest request) {
    Collection<IndividualCandidacyProcess> processes = super.getChildProcesses(process, request);

    List<IndividualCandidacyProcess> result = new ArrayList<IndividualCandidacyProcess>();

    CollectionUtils.select(processes, new Predicate() {

        @Override
        public boolean evaluate(Object arg0) {
            IndividualCandidacyProcess child = (IndividualCandidacyProcess) arg0;

            return ((MobilityApplicationProcess) process).getDegreesAssociatedToTeacherAsCoordinator(getTeacher()).contains(
                    ((MobilityIndividualApplicationProcess) child).getCandidacy().getSelectedDegree());
        }

    }, result);

    return result;
}
 
Example 6
Source File: Table.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a list of non-unique indices on this table.
 * 
 * @return The unique indices
 */
public Index[] getNonUniqueIndices()
{
    Collection nonUniqueIndices = CollectionUtils.select(_indices, new Predicate() {
        public boolean evaluate(Object input) {
            return !((Index)input).isUnique();
        }
    });

    return (Index[])nonUniqueIndices.toArray(new Index[nonUniqueIndices.size()]);
}
 
Example 7
Source File: Table.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a list of unique indices on this table.
 * 
 * @return The unique indices
 */
public Index[] getUniqueIndices()
{
    Collection uniqueIndices = CollectionUtils.select(_indices, new Predicate() {
        public boolean evaluate(Object input) {
            return ((Index)input).isUnique();
        }
    });

    return (Index[])uniqueIndices.toArray(new Index[uniqueIndices.size()]);
}
 
Example 8
Source File: Table.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the primary key columns of this table.
 * 
 * @return The primary key columns
 */
public Column[] getPrimaryKeyColumns()
{
    Collection pkColumns = CollectionUtils.select(_columns, new Predicate() {
        public boolean evaluate(Object input) {
            return ((Column)input).isPrimaryKey();
        }
    });

    return (Column[])pkColumns.toArray(new Column[pkColumns.size()]);
}
 
Example 9
Source File: Table.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the auto increment columns in this table. If none are found,
 * then an empty array will be returned.
 * 
 * @return The auto increment columns
 */
public Column[] getAutoIncrementColumns()
{
    Collection autoIncrColumns = CollectionUtils.select(_columns, new Predicate() {
        public boolean evaluate(Object input) {
            return ((Column)input).isAutoIncrement();
        }
    });

    return (Column[])autoIncrColumns.toArray(new Column[autoIncrColumns.size()]);
}
 
Example 10
Source File: MobilityApplicationProcess.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public List<MobilityCoordinator> getErasmusCoordinatorForTeacher(final Teacher teacher) {
    return new ArrayList<MobilityCoordinator>(CollectionUtils.select(getCoordinatorsSet(), new Predicate() {

        @Override
        public boolean evaluate(Object arg0) {
            return ((MobilityCoordinator) arg0).getTeacher() == teacher;
        }

    }));
}
 
Example 11
Source File: Teacher.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public List<Professorship> getDegreeProfessorshipsByExecutionPeriod(final ExecutionSemester executionSemester) {
    return (List<Professorship>) CollectionUtils.select(getProfessorships(), new Predicate() {
        @Override
        public boolean evaluate(Object arg0) {
            Professorship professorship = (Professorship) arg0;
            return professorship.getExecutionCourse().getExecutionPeriod() == executionSemester
                    && !professorship.getExecutionCourse().isMasterDegreeDFAOrDEAOnly();
        }
    });
}
 
Example 12
Source File: PlatformImplBase.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
     * Returns all identity properties whose value were defined by the database and which
     * now need to be read back from the DB.
     * 
     * @param model     The database model
     * @param dynaClass The dyna class
     * @param bean      The bean
     * @return The columns
     */
    private Column[] getRelevantIdentityColumns(Database model, SqlDynaClass dynaClass, final DynaBean bean)
    {
        SqlDynaProperty[] properties = dynaClass.getSqlDynaProperties();

        Collection relevantProperties = CollectionUtils.select(Arrays.asList(properties), new Predicate() {
            public boolean evaluate(Object input) {
                SqlDynaProperty prop = (SqlDynaProperty)input;

                // we only want those identity columns that were really specified by the DB
                // if the platform allows specification of values for identity columns
                // in INSERT/UPDATE statements, then we need to filter the corresponding
                // columns out
                return prop.getColumn().isAutoIncrement() &&
// GemStone changes BEGIN
                       // allow using ALTER TABLE for identity columns
                       // after initial data loading
                       (!isAddIdentityUsingAlterTableOn() ||
                           !getPlatformInfo()
                               .isAddingIdentityUsingAlterTableSupported()) &&
                       (!isIdentityOverrideOn() ||
                           !getPlatformInfo().isIdentityOverrideAllowed() ||
                           (bean.get(prop.getName()) == null));
                       /* (original code)
                       (!isIdentityOverrideOn() || !getPlatformInfo().isIdentityOverrideAllowed() || (bean.get(prop.getName()) == null));
                       */
// GemStone changes END
            }
        });

        Column[] columns = new Column[relevantProperties.size()];
        int      idx     = 0;

        for (Iterator propIt = relevantProperties.iterator(); propIt.hasNext(); idx++)
        {
            columns[idx] = ((SqlDynaProperty)propIt.next()).getColumn();
        }
        return columns;
    }
 
Example 13
Source File: EventReportQueueJob.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static List<EventReportQueueJob> retrieveAllGeneratedReports() {
    List<EventReportQueueJob> reports = new ArrayList<>();

    CollectionUtils.select(Bennu.getInstance().getQueueJobSet(), new Predicate() {

        @Override
        public boolean evaluate(Object arg0) {
            return arg0 instanceof EventReportQueueJob;
        }

    }, reports);

    return reports;
}
 
Example 14
Source File: DegreeCurricularPlan.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public List<Branch> getCommonAreas() {
    return (List<Branch>) CollectionUtils.select(getAreasSet(), new Predicate() {
        @Override
        public boolean evaluate(Object obj) {
            Branch branch = (Branch) obj;
            if (branch.getBranchType() == null) {
                return branch.getName().equals("") && branch.getCode().equals("");
            }
            return branch.getBranchType().equals(org.fenixedu.academic.domain.branch.BranchType.COMNBR);

        }
    });
}
 
Example 15
Source File: PublicPhdProgramCandidacyProcessDA.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
private List<PhdCandidacyPeriod> getCandidacyPeriods() {
    List<PhdCandidacyPeriod> candidacyPeriodList = new ArrayList<PhdCandidacyPeriod>();

    CollectionUtils.select(Bennu.getInstance().getCandidacyPeriodsSet(), new Predicate() {

        @Override
        public boolean evaluate(Object arg0) {
            return arg0 instanceof PhdCandidacyPeriod;
        }

    }, candidacyPeriodList);

    return candidacyPeriodList;
}
 
Example 16
Source File: Table.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the required (not-nullable) columns in this table. If none are found,
 * then an empty array will be returned.
 * 
 * @return The required columns
 */
public Column[] getRequiredColumns()
{
    Collection requiredColumns = CollectionUtils.select(_columns, new Predicate() {
        public boolean evaluate(Object input) {
            return ((Column)input).isRequired();
        }
    });

    return (Column[])requiredColumns.toArray(new Column[requiredColumns.size()]);
}
 
Example 17
Source File: MobilityApplicationProcess.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public List<ErasmusCandidacyProcessReport> getDoneReports() {
    List<ErasmusCandidacyProcessReport> jobList = new ArrayList<ErasmusCandidacyProcessReport>();

    CollectionUtils.select(getErasmusCandidacyProcessReportsSet(), new Predicate() {

        @Override
        public boolean evaluate(Object arg0) {
            return ((QueueJob) arg0).getDone();
        }
    }, jobList);

    return jobList;
}
 
Example 18
Source File: MobilityIndividualApplicationProcess.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public List<ErasmusAlert> getAlertsNotViewed() {
    List<ErasmusAlert> alertsNotViewed = new ArrayList<ErasmusAlert>();

    CollectionUtils.select(getAlertSet(), arg0 -> {
        ErasmusAlert alert = (ErasmusAlert) arg0;
        return alert.isToFire();
    }, alertsNotViewed);

    Collections.sort(alertsNotViewed, Collections.reverseOrder(ErasmusAlert.WHEN_CREATED_COMPARATOR));

    return alertsNotViewed;
}
 
Example 19
Source File: PlatformImplBase.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
     * Returns all properties where the column is not non-autoincrement and for which the bean
     * either has a value or the column hasn't got a default value, for the given dyna class.
     * 
     * @param model     The database model
     * @param dynaClass The dyna class
     * @param bean      The bean
     * @return The properties
     */
    private SqlDynaProperty[] getPropertiesForInsertion(Database model, SqlDynaClass dynaClass, final DynaBean bean)
    {
        SqlDynaProperty[] properties = dynaClass.getSqlDynaProperties();

        Collection result = CollectionUtils.select(Arrays.asList(properties), new Predicate() {
            public boolean evaluate(Object input) {
                SqlDynaProperty prop = (SqlDynaProperty)input;

                if (bean.get(prop.getName()) != null)
                {
                    // we ignore properties for which a value is present in the bean
                    // only if they are identity and identity override is off or
                    // the platform does not allow the override of the auto-increment
                    // specification
                    return !prop.getColumn().isAutoIncrement() ||
// GemStone changes BEGIN
                        // allow using ALTER TABLE for identity columns
                        // after initial data loading
                           (isIdentityOverrideOn() &&
                               getPlatformInfo().isIdentityOverrideAllowed()) ||
                           (isAddIdentityUsingAlterTableOn() &&
                               getPlatformInfo()
                                   .isAddingIdentityUsingAlterTableSupported());
                           /* (original code)
                           (isIdentityOverrideOn() && getPlatformInfo().isIdentityOverrideAllowed());
                           */
// GemStone changes END
                }
                else
                {
                    // we also return properties without a value in the bean
                    // if they ain't auto-increment and don't have a default value
                    // in this case, a NULL is inserted
                    return !prop.getColumn().isAutoIncrement() &&
                           (prop.getColumn().getDefaultValue() == null);
                }
            }
        });

        return (SqlDynaProperty[])result.toArray(new SqlDynaProperty[result.size()]);
    }
 
Example 20
Source File: HibernateXmlConverter.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param writer
 * @param includeHistory
 * @param session
 * @throws DataAccessException
 * @throws HibernateException
 */
private void writeObjects(final Writer writer, final boolean includeHistory, final Session session, final boolean preserveIds)
    throws DataAccessException, HibernateException
    {
  // Container für die Objekte
  final List<Object> all = new ArrayList<Object>();
  final XStream stream = initXStream(session, true);
  final XStream defaultXStream = initXStream(session, false);

  session.flush();
  // Alles laden
  final List<Class< ? >> entities = new ArrayList<Class< ? >>();
  entities.addAll(HibernateEntities.instance().getOrderedEntities());
  entities.addAll(HibernateEntities.instance().getOrderedHistoryEntities());
  for (final Class< ? > entityClass : entities) {
    final String entitySimpleName = entityClass.getSimpleName();
    final String entityType = entityClass.getName();
    if (includeHistory == false && entityType.startsWith("de.micromata.hibernate.history.") == true) {
      // Skip history entries.
      continue;
    }
    List< ? > list = session.createQuery("select o from " + entityType + " o").setReadOnly(true).list();
    list = (List< ? >) CollectionUtils.select(list, PredicateUtils.uniquePredicate());
    final int size = list.size();
    log.info("Writing " + size + " objects");
    for (final Iterator< ? > it = list.iterator(); it.hasNext();) {
      final Object obj = it.next();
      if (log.isDebugEnabled()) {
        log.debug("loaded object " + obj);
      }
      Hibernate.initialize(obj);
      final Class< ? > targetClass = HibernateProxyHelper.getClassWithoutInitializingProxy(obj);
      final ClassMetadata classMetadata = session.getSessionFactory().getClassMetadata(targetClass);
      if (classMetadata == null) {
        log.fatal("Can't init " + obj + " of type " + targetClass);
        continue;
      }
      // initalisierung des Objekts...
      defaultXStream.marshal(obj, new CompactWriter(new NullWriter()));

      if (preserveIds == false) {
        // Nun kann die ID gelöscht werden
        classMetadata.setIdentifier(obj, null, EntityMode.POJO);
      }
      if (log.isDebugEnabled()) {
        log.debug("loading evicted object " + obj);
      }
      if (this.ignoreFromTopLevelListing.contains(targetClass) == false) {
        all.add(obj);
      }
    }
  }
  // und schreiben
  try {
    writer.write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
  } catch (final IOException ex) {
    // ignore, will fail on stream.marshal()
  }
  log.info("Wrote " + all.size() + " objects");
  final MarshallingStrategy marshallingStrategy = new ProxyIdRefMarshallingStrategy();
  stream.setMarshallingStrategy(marshallingStrategy);
  stream.marshal(all, new PrettyPrintWriter(writer));
    }