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

The following examples show how to use org.apache.commons.collections.CollectionUtils#collect() . 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: StudentCurricularPlan.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
final public boolean isCurricularCourseApproved(CurricularCourse curricularCourse) {
    List studentApprovedEnrollments = getStudentEnrollmentsWithApprovedState();

    List<CurricularCourse> result =
            (List<CurricularCourse>) CollectionUtils.collect(studentApprovedEnrollments, new Transformer() {
                @Override
                final public Object transform(Object obj) {
                    Enrolment enrollment = (Enrolment) obj;

                    return enrollment.getCurricularCourse();

                }
            });

    return isApproved(curricularCourse, result);
}
 
Example 2
Source File: ReadShiftsByClass.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Atomic
public static Object run(InfoClass infoClass) {
    check(RolePredicates.RESOURCE_ALLOCATION_MANAGER_PREDICATE);
    SchoolClass schoolClass = FenixFramework.getDomainObject(infoClass.getExternalId());

    Collection<Shift> shifts = schoolClass.getAssociatedShiftsSet();

    return CollectionUtils.collect(shifts, new Transformer() {
        @Override
        public Object transform(Object arg0) {
            Shift shift = (Shift) arg0;
            InfoShift infoShift = InfoShift.newInfoFromDomain(shift);
            return infoShift;
        }
    });
}
 
Example 3
Source File: ReadActiveDegreeCurricularPlansByDegreeType.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static Collection<InfoDegreeCurricularPlan> getActiveDegreeCurricularPlansByDegreeType(
        Predicate<DegreeType> degreeType, AccessControlPredicate<Object> permission) {
    List<DegreeCurricularPlan> degreeCurricularPlans = new ArrayList<DegreeCurricularPlan>();
    for (DegreeCurricularPlan dcp : DegreeCurricularPlan.readByDegreeTypeAndState(degreeType,
            DegreeCurricularPlanState.ACTIVE)) {
        if (permission != null) {
            if (!permission.evaluate(dcp.getDegree())) {
                continue;
            }
        }
        degreeCurricularPlans.add(dcp);
    }

    return CollectionUtils.collect(degreeCurricularPlans, new Transformer() {

        @Override
        public Object transform(Object arg0) {
            DegreeCurricularPlan degreeCurricularPlan = (DegreeCurricularPlan) arg0;
            return InfoDegreeCurricularPlan.newInfoFromDomain(degreeCurricularPlan);
        }

    });
}
 
Example 4
Source File: ReadStudentsFromDegreeCurricularPlan.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected List run(String degreeCurricularPlanID) throws FenixServiceException {
    // Read the Students
    DegreeCurricularPlan degreeCurricularPlan = FenixFramework.getDomainObject(degreeCurricularPlanID);

    Collection students = degreeCurricularPlan.getStudentCurricularPlansSet();

    if ((students == null) || (students.isEmpty())) {
        throw new NonExistingServiceException();
    }

    return (List) CollectionUtils.collect(students, new Transformer() {
        @Override
        public Object transform(Object arg0) {
            StudentCurricularPlan studentCurricularPlan = (StudentCurricularPlan) arg0;
            return InfoStudentCurricularPlan.newInfoFromDomain(studentCurricularPlan);
        }

    });
}
 
Example 5
Source File: Util.java    From semanticMDR with GNU General Public License v3.0 5 votes vote down vote up
public <T extends MDRResource> List<T> createList(ExtendedIterator<? extends RDFNode> it,
		Class<T> cls) throws MDRException {

	List<T> newList = new ArrayList<T>();
	try {
		Transformer transformer = transformerMap.get(cls);
		CollectionUtils.collect(it, transformer, newList);
	} catch (Exception e) {
		throw new MDRException(e);
	}
	return newList;
}
 
Example 6
Source File: DisplayHistoryEntry.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
private Object toShortNameOfList(final Object value)
{
  if (value instanceof Collection< ? >) {
    return CollectionUtils.collect((Collection< ? >) value, new Transformer() {
      public Object transform(final Object input)
      {
        return toShortName(input);
      }
    });
  }
  return value;
}
 
Example 7
Source File: StudentCurricularPlan.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
private List<CurricularCourse> getStudentNotNeedToEnrollCurricularCourses() {
    return (List<CurricularCourse>) CollectionUtils.collect(getNotNeedToEnrollCurricularCoursesSet(), new Transformer() {
        @Override
        final public Object transform(Object obj) {
            NotNeedToEnrollInCurricularCourse notNeedToEnrollInCurricularCourse = (NotNeedToEnrollInCurricularCourse) obj;
            return notNeedToEnrollInCurricularCourse.getCurricularCourse();
        }
    });
}
 
Example 8
Source File: StudentCurricularPlan.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
final public boolean isCurricularCourseEnrolled(CurricularCourse curricularCourse) {
    List result = (List) CollectionUtils.collect(getStudentEnrollmentsWithEnrolledState(), new Transformer() {
        @Override
        final public Object transform(Object obj) {
            Enrolment enrollment = (Enrolment) obj;
            return enrollment.getCurricularCourse();
        }
    });

    return result.contains(curricularCourse);
}
 
Example 9
Source File: StudentCurricularPlan.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
final public boolean isEquivalentAproved(CurricularCourse curricularCourse) {
    List studentApprovedEnrollments = getStudentEnrollmentsWithApprovedState();

    List<CurricularCourse> result = (List) CollectionUtils.collect(studentApprovedEnrollments, new Transformer() {
        @Override
        final public Object transform(Object obj) {
            Enrolment enrollment = (Enrolment) obj;

            return enrollment.getCurricularCourse();

        }
    });

    return isThisCurricularCoursesInTheList(curricularCourse, result) || hasEquivalenceInNotNeedToEnroll(curricularCourse);
}
 
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<Degree> getDegreesAssociatedToTeacherAsCoordinator(final Teacher teacher) {
    List<MobilityCoordinator> coordinators = getErasmusCoordinatorForTeacher(teacher);

    return new ArrayList<Degree>(CollectionUtils.collect(coordinators, new Transformer() {

        @Override
        public Object transform(Object arg0) {
            return ((MobilityCoordinator) arg0).getDegree();
        }
    }));
}
 
Example 11
Source File: SeperateExecutionCourse.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static Set<String> getExecutionCourseCodes(ExecutionSemester executionSemester) {
    Collection<ExecutionCourse> executionCourses = executionSemester.getAssociatedExecutionCoursesSet();
    return new HashSet<String>(CollectionUtils.collect(executionCourses, new Transformer() {
        @Override
        public Object transform(Object arg0) {
            ExecutionCourse executionCourse = (ExecutionCourse) arg0;
            return executionCourse.getSigla().toUpperCase();
        }
    }));
}
 
Example 12
Source File: InfoExam.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public List getAssociatedRooms() {
    return (List) CollectionUtils.collect(super.getWrittenEvaluationSpaceOccupations(), new Transformer() {

        @Override
        public Object transform(Object arg0) {
            InfoRoomOccupation roomOccupation = (InfoRoomOccupation) arg0;
            return roomOccupation.getInfoRoom();
        }
    });
}
 
Example 13
Source File: DocumentTypePermissionServiceImpl.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Converts list of RouteNodeInstance objects to a list of the route node names
 * @param routeNodeInstances the list RouteNodeInstance objects, may be null
 * @return non-null, possibly empty, Collection of routenode names
 */
protected Collection<String> toRouteNodeNames(Collection<RouteNodeInstance> routeNodeInstances) {
    if (routeNodeInstances != null) {
        return CollectionUtils.collect(routeNodeInstances, new Transformer() {
            @Override
            public Object transform(Object input) {
                return ((RouteNodeInstance) input).getName();
            }
        });
    } else {
        return Collections.EMPTY_LIST;
    }
}
 
Example 14
Source File: AtlasEntityStoreV2Test.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = "testCreate")
public void associateSameTagToMultipleEntities() throws AtlasBaseException {
    final String TAG_NAME            = "tagx";
    final String TAG_ATTRIBUTE_NAME  = "testAttribute";
    final String TAG_ATTRIBUTE_VALUE = "test-string";

    createTag(TAG_NAME, "string");
    List<AtlasClassification> addedClassifications = new ArrayList<>();
    addedClassifications.add(new AtlasClassification(TAG_NAME, TAG_ATTRIBUTE_NAME, TAG_ATTRIBUTE_VALUE));

    entityStore.addClassifications(dbEntityGuid, addedClassifications);
    entityStore.addClassifications(tblEntityGuid, addedClassifications);

    AtlasEntity dbEntityFromDb  = getEntityFromStore(dbEntityGuid);
    AtlasEntity tblEntityFromDb = getEntityFromStore(tblEntityGuid);

    Set<String> actualDBClassifications  = new HashSet<>(CollectionUtils.collect(dbEntityFromDb.getClassifications(), o -> ((AtlasClassification) o).getTypeName()));
    Set<String> actualTblClassifications = new HashSet<>(CollectionUtils.collect(tblEntityFromDb.getClassifications(), o -> ((AtlasClassification) o).getTypeName()));

    assertTrue(actualDBClassifications.contains(TAG_NAME));
    assertTrue(actualTblClassifications.contains(TAG_NAME));

    Set<String> actualDBAssociatedEntityGuid  = new HashSet<>(CollectionUtils.collect(dbEntityFromDb.getClassifications(), o -> ((AtlasClassification) o).getEntityGuid()));
    Set<String> actualTblAssociatedEntityGuid = new HashSet<>(CollectionUtils.collect(tblEntityFromDb.getClassifications(), o -> ((AtlasClassification) o).getEntityGuid()));

    assertTrue(actualDBAssociatedEntityGuid.contains(dbEntityGuid));
    assertTrue(actualTblAssociatedEntityGuid.contains(tblEntityGuid));

    entityStore.deleteClassification(dbEntityGuid, TAG_NAME);
    entityStore.deleteClassification(tblEntityGuid, TAG_NAME);
}
 
Example 15
Source File: AtlasEntityStoreV2Test.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = "testCreate")
public void associateMultipleTagsToOneEntity() throws AtlasBaseException {
    final String TAG_NAME              = "tag_xy";
    final String TAG_NAME_2            = TAG_NAME + "_2";
    final String TAG_ATTRIBUTE_NAME    = "testAttribute";
    final String TAG_ATTRIBUTE_VALUE   = "test-string";
    final String TAG_ATTRIBUTE_VALUE_2 = TAG_ATTRIBUTE_VALUE + "-2";

    createTag(TAG_NAME, "string");
    createTag(TAG_NAME_2, "string");

    List<AtlasClassification> addedClassifications = new ArrayList<>();
    addedClassifications.add(new AtlasClassification(TAG_NAME, TAG_ATTRIBUTE_NAME, TAG_ATTRIBUTE_VALUE));
    addedClassifications.add(new AtlasClassification(TAG_NAME_2, TAG_ATTRIBUTE_NAME, TAG_ATTRIBUTE_VALUE_2));
    entityStore.addClassifications(dbEntityGuid, addedClassifications);

    AtlasEntity dbEntityFromDb = getEntityFromStore(dbEntityGuid);

    List<String> actualClassifications = (List<String>) CollectionUtils.collect(dbEntityFromDb.getClassifications(), o -> ((AtlasClassification) o).getTypeName());
    Set<String> classificationSet = new HashSet<>(actualClassifications);
    assertTrue(classificationSet.contains(TAG_NAME));
    assertTrue(classificationSet.contains(TAG_NAME_2));

    for (String actualClassificationName : actualClassifications) {
        entityStore.deleteClassification(dbEntityGuid, actualClassificationName);
    }
}
 
Example 16
Source File: ApacheCommonsConfigurationPropertySource.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 4 votes vote down vote up
@Override
public String[] getPropertyNames() {
    ArrayList<String> keys = new ArrayList<>();
    CollectionUtils.collect(this.source.getKeys(), NOPTransformer.getInstance(), keys);
    return keys.toArray(new String[keys.size()]);
}
 
Example 17
Source File: ApacheCommonsConfigurationPropertySource.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 4 votes vote down vote up
@Override
public String[] getPropertyNames() {
    ArrayList<String> keys = new ArrayList<>();
    CollectionUtils.collect(this.source.getKeys(), NOPTransformer.getInstance(), keys);
    return keys.toArray(new String[keys.size()]);
}
 
Example 18
Source File: ApacheCommonsConfigurationPropertySource.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 4 votes vote down vote up
@Override
public String[] getPropertyNames() {
    ArrayList<String> keys = new ArrayList<>();
    CollectionUtils.collect(this.source.getKeys(), NOPTransformer.getInstance(), keys);
    return keys.toArray(new String[keys.size()]);
}
 
Example 19
Source File: ApacheCommonsConfigurationPropertySource.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 4 votes vote down vote up
@Override
public String[] getPropertyNames() {
    ArrayList<String> keys = new ArrayList<>();
    CollectionUtils.collect(this.source.getKeys(), NOPTransformer.getInstance(), keys);
    return keys.toArray(new String[keys.size()]);
}