Java Code Examples for org.apache.commons.collections.CollectionUtils#find()
The following examples show how to use
org.apache.commons.collections.CollectionUtils#find() .
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: FindElementsInList.java From levelup-java-examples with Apache License 2.0 | 6 votes |
@Test public void find_elements_in_list_with_apachecommons () { List <Integer> numbers = Lists.newArrayList( new Integer(1), new Integer(2), new Integer(3)); Integer value = (Integer) CollectionUtils.find(numbers, new org.apache.commons.collections.Predicate() { public boolean evaluate(Object number) { return ((Integer)number).intValue() == 3 ; } }); assertEquals(new Integer(3), value); }
Example 2
Source File: CurricularCourseScopesForPrintDTO.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 6 votes |
private CurricularYearForPrintDTO getSelectedCurricularYear(final InfoCurricularCourseScope scope, DegreeCurricularPlanForPrintDTO selectedCurricularPlan) { CurricularYearForPrintDTO selectedCurricularYear = (CurricularYearForPrintDTO) CollectionUtils.find(selectedCurricularPlan.getYears(), new Predicate() { @Override public boolean evaluate(Object arg0) { CurricularYearForPrintDTO curricularYearForPrintDTO = (CurricularYearForPrintDTO) arg0; if (curricularYearForPrintDTO.getYear().equals( scope.getInfoCurricularSemester().getInfoCurricularYear().getYear())) { return true; } return false; } }); if (selectedCurricularYear == null) { selectedCurricularYear = new CurricularYearForPrintDTO(scope.getInfoCurricularSemester().getInfoCurricularYear().getYear()); selectedCurricularPlan.getYears().add(selectedCurricularYear); } return selectedCurricularYear; }
Example 3
Source File: CurricularCourseScopesForPrintDTO.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 6 votes |
private BranchForPrintDTO getSelectedBranch(final InfoCurricularCourseScope scope, CurricularYearForPrintDTO selectedCurricularYear) { BranchForPrintDTO selectedBranch = (BranchForPrintDTO) CollectionUtils.find(selectedCurricularYear.getBranches(), new Predicate() { @Override public boolean evaluate(Object arg0) { BranchForPrintDTO branchForPrintDTO = (BranchForPrintDTO) arg0; if (branchForPrintDTO.getName().equals(scope.getInfoBranch().getName())) { return true; } return false; } }); if (selectedBranch == null) { selectedBranch = new BranchForPrintDTO(scope.getInfoBranch().getName()); selectedCurricularYear.getBranches().add(selectedBranch); } return selectedBranch; }
Example 4
Source File: AddressServiceTest.java From java-client with Apache License 2.0 | 6 votes |
@Test public void testGetAddress() throws BlockCypherException, IOException { String addressM = "mvYwMT3aZ5jNcRNNjv7ckxjbqMDtvQbAHz"; Address address = blockCypherContext.getAddressService().getAddress(addressM); logger.info(MessageFormat.format("Adress {0} has the following transactions: ", addressM)); logger.info(StringUtils.join(CollectionUtils.collect(address.getTxrefs(), TransformerUtils.invokerTransformer("getTxHash")), "\n")); TransactionSummary transactionSummary = (TransactionSummary) CollectionUtils.find(address.getTxrefs(), new Predicate() { public boolean evaluate(Object object) { return ((TransactionSummary) object).getTxHash() .equals("f8c652d90b1aa2e510ab0963525836e1e1bcc1f93f7beca65a8902c54ed77d5e"); } }); assertNotNull(transactionSummary); assertEquals(new Long(271558), transactionSummary.getBlockHeight()); assertEquals(new BigDecimal(100270000), transactionSummary.getValue()); }
Example 5
Source File: PreferencesLocaleHandler.java From spacewalk with GNU General Public License v2.0 | 6 votes |
/** * Set the TimeZone for the given user. * @param loggedInUser The current user * in user. * @param login The login of the user whose timezone will be changed. * @param tzid TimeZone id * @return Returns 1 if successful (exception otherwise) * * @xmlrpc.doc Set a user's timezone. * @xmlrpc.param #param("string", "sessionKey") * @xmlrpc.param #param_desc("string", "login", "User's login name.") * @xmlrpc.param #param_desc("int", "tzid" "Timezone ID. (from listTimeZones)") * @xmlrpc.returntype #return_int_success() */ public int setTimeZone(User loggedInUser, String login, Integer tzid) { List tzs = UserManager.lookupAllTimeZones(); Object o = CollectionUtils.find(tzs, new TzPredicate(tzid)); if (o == null) { throw new InvalidTimeZoneException(tzid); } User target = XmlRpcUserHelper.getInstance() .lookupTargetUser(loggedInUser, login); target.setTimeZone((RhnTimeZone)o); UserManager.storeUser(target); return 1; }
Example 6
Source File: PreferencesLocaleHandler.java From uyuni with GNU General Public License v2.0 | 6 votes |
/** * Set the TimeZone for the given user. * @param loggedInUser The current user * in user. * @param login The login of the user whose timezone will be changed. * @param tzid TimeZone id * @return Returns 1 if successful (exception otherwise) * * @xmlrpc.doc Set a user's timezone. * @xmlrpc.param #param("string", "sessionKey") * @xmlrpc.param #param_desc("string", "login", "User's login name.") * @xmlrpc.param #param_desc("int", "tzid" "Timezone ID. (from listTimeZones)") * @xmlrpc.returntype #return_int_success() */ public int setTimeZone(User loggedInUser, String login, Integer tzid) { List tzs = UserManager.lookupAllTimeZones(); Object o = CollectionUtils.find(tzs, new TzPredicate(tzid)); if (o == null) { throw new InvalidTimeZoneException(tzid); } User target = XmlRpcUserHelper.getInstance() .lookupTargetUser(loggedInUser, login); target.setTimeZone((RhnTimeZone)o); UserManager.storeUser(target); return 1; }
Example 7
Source File: PreferencesLocaleHandler.java From spacewalk with GNU General Public License v2.0 | 5 votes |
/** * Set the language the user will display in the user interface. * @param loggedInUser The current user * in user. * @param login The login of the user whose language will be changed. * @param locale Locale code to be used as the users language. * @return Returns 1 if successful (exception otherwise) * * @xmlrpc.doc Set a user's locale. * @xmlrpc.param #param("string", "sessionKey") * @xmlrpc.param #param_desc("string", "login", "User's login name.") * @xmlrpc.param #param_desc("string", "locale", "Locale to set. (from listLocales)") * @xmlrpc.returntype #return_int_success() */ public int setLocale(User loggedInUser, String login, String locale) { LocalizationService ls = LocalizationService.getInstance(); List locales = ls.getConfiguredLocales(); Object o = CollectionUtils.find(locales, new LocalePredicate(locale)); if (o == null) { throw new InvalidLocaleCodeException(locale); } User target = XmlRpcUserHelper.getInstance() .lookupTargetUser(loggedInUser, login); target.setPreferredLocale(locale); UserManager.storeUser(target); return 1; }
Example 8
Source File: ShiftStudentEnrollmentManagerLookupDispatchAction.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
private SchoolClass searchSchoolClassFrom(final List<SchoolClass> schoolClassesToEnrol, final String classId) { return (SchoolClass) CollectionUtils.find(schoolClassesToEnrol, new Predicate() { @Override public boolean evaluate(Object object) { return ((SchoolClass) object).getExternalId().equals(classId); } }); }
Example 9
Source File: ShiftStudentEnrollmentManagerLookupDispatchAction.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
private SchoolClass searchSchoolClassFrom(final List<SchoolClass> schoolClassesToEnrol, final String classId) { return (SchoolClass) CollectionUtils.find(schoolClassesToEnrol, new Predicate() { @Override public boolean evaluate(Object object) { return ((SchoolClass) object).getExternalId().equals(classId); } }); }
Example 10
Source File: Teacher.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
public Professorship getProfessorshipByExecutionCourse(final ExecutionCourse executionCourse) { return (Professorship) CollectionUtils.find(getProfessorships(), new Predicate() { @Override public boolean evaluate(Object arg0) { Professorship professorship = (Professorship) arg0; return professorship.getExecutionCourse() == executionCourse; } }); }
Example 11
Source File: ExternalPhdProgram.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
public static ExternalPhdProgram readExternalPhdProgramByName(final String name) { return (ExternalPhdProgram) CollectionUtils.find(Bennu.getInstance().getExternalPhdProgramsSet(), new Predicate() { @Override public boolean evaluate(Object object) { return name.equals(((ExternalPhdProgram) object).getName().getContent()); } }); }
Example 12
Source File: InfoReimbursementGuide.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
/** * @return */ public InfoReimbursementGuideSituation getActiveInfoReimbursementGuideSituation() { return (InfoReimbursementGuideSituation) CollectionUtils.find(getInfoReimbursementGuideSituations(), new Predicate() { @Override public boolean evaluate(Object obj) { InfoReimbursementGuideSituation situation = (InfoReimbursementGuideSituation) obj; return situation.getState().getState().intValue() == State.ACTIVE; } }); }
Example 13
Source File: ThirdeyeAvroUtils.java From incubator-pinot with Apache License 2.0 | 5 votes |
/** * Helper removed from AvroRecordReader in b19a0965044d3e3f4f1541cc4cd9ea60b96a4b99 * * @param fieldSchema * @return */ private static org.apache.avro.Schema extractSchemaFromUnionIfNeeded(org.apache.avro.Schema fieldSchema) { if ((fieldSchema).getType() == Schema.Type.UNION) { fieldSchema = ((org.apache.avro.Schema) CollectionUtils.find(fieldSchema.getTypes(), new Predicate() { @Override public boolean evaluate(Object object) { return ((org.apache.avro.Schema) object).getType() != Schema.Type.NULL; } })); } return fieldSchema; }
Example 14
Source File: SegmentTestUtils.java From incubator-pinot with Apache License 2.0 | 5 votes |
private static org.apache.avro.Schema extractSchemaFromUnionIfNeeded(org.apache.avro.Schema fieldSchema) { if ((fieldSchema).getType() == Type.UNION) { fieldSchema = ((org.apache.avro.Schema) CollectionUtils.find(fieldSchema.getTypes(), new Predicate() { @Override public boolean evaluate(Object object) { return ((org.apache.avro.Schema) object).getType() != Type.NULL; } })); } return fieldSchema; }
Example 15
Source File: TypeScriptPluginTest.java From SonarTsPlugin with MIT License | 5 votes |
private static Property findPropertyByName(Property[] properties, final String name) { return (Property) CollectionUtils.find(Arrays.asList(properties), new Predicate() { @Override public boolean evaluate(Object arg0) { return ((Property) arg0).key().equals(name); } }); }
Example 16
Source File: Branch.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
private Boolean hasCurricularCourseCommonBranchInAnyCurricularCourseScope(CurricularCourse curricularCourse, final Branch commonBranch) { return ((CurricularCourseScope) CollectionUtils.find(curricularCourse.getScopesSet(), new Predicate() { @Override public boolean evaluate(Object o) { CurricularCourseScope ccs = (CurricularCourseScope) o; return ccs.getBranch().equals(commonBranch); } }) != null); }
Example 17
Source File: ReimbursementGuide.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
public ReimbursementGuideSituation getActiveReimbursementGuideSituation() { return (ReimbursementGuideSituation) CollectionUtils.find(getReimbursementGuideSituationsSet(), new Predicate() { @Override public boolean evaluate(Object obj) { ReimbursementGuideSituation situation = (ReimbursementGuideSituation) obj; return situation.getState().getState().equals(State.ACTIVE); } }); }
Example 18
Source File: ExternalPhdProgram.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
public static ExternalPhdProgram readExternalPhdProgramByAcronym(final String acronym) { return (ExternalPhdProgram) CollectionUtils.find(Bennu.getInstance().getExternalPhdProgramsSet(), new Predicate() { @Override public boolean evaluate(Object object) { return acronym.equals(((ExternalPhdProgram) object).getAcronym()); } }); }
Example 19
Source File: PreferencesLocaleHandler.java From uyuni with GNU General Public License v2.0 | 5 votes |
/** * Set the language the user will display in the user interface. * @param loggedInUser The current user * in user. * @param login The login of the user whose language will be changed. * @param locale Locale code to be used as the users language. * @return Returns 1 if successful (exception otherwise) * * @xmlrpc.doc Set a user's locale. * @xmlrpc.param #param("string", "sessionKey") * @xmlrpc.param #param_desc("string", "login", "User's login name.") * @xmlrpc.param #param_desc("string", "locale", "Locale to set. (from listLocales)") * @xmlrpc.returntype #return_int_success() */ public int setLocale(User loggedInUser, String login, String locale) { LocalizationService ls = LocalizationService.getInstance(); List locales = ls.getConfiguredLocales(); Object o = CollectionUtils.find(locales, new LocalePredicate(locale)); if (o == null) { throw new InvalidLocaleCodeException(locale); } User target = XmlRpcUserHelper.getInstance() .lookupTargetUser(loggedInUser, login); target.setPreferredLocale(locale); UserManager.storeUser(target); return 1; }
Example 20
Source File: ClassificationAssociator.java From atlas with Apache License 2.0 | 4 votes |
private V findFrom(List<V> reference, V check) { return (V) CollectionUtils.find(reference, ox -> ((V) ox).getTypeName().equals(check.getTypeName())); }