├── .asf.yaml ├── .github └── GH-ROBOTS.txt ├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE.txt ├── NOTICE.txt ├── README.md ├── RELEASE-NOTES.txt ├── SECURITY.md ├── api ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── apache │ └── commons │ └── functor │ ├── BinaryFunction.java │ ├── BinaryFunctor.java │ ├── BinaryPredicate.java │ ├── BinaryProcedure.java │ ├── Function.java │ ├── Functor.java │ ├── NullaryFunction.java │ ├── NullaryFunctor.java │ ├── NullaryPredicate.java │ ├── NullaryProcedure.java │ ├── Predicate.java │ ├── Procedure.java │ ├── UnaryFunctor.java │ └── package-info.java ├── build-tools ├── pom.xml └── src │ └── main │ └── resources │ └── org │ └── apache │ └── commons │ └── functor │ ├── checkstyle-suppressions.xml │ ├── checkstyle.xml │ ├── fb-excludes.xml │ └── license-header.txt ├── core ├── pom.xml └── src │ ├── main │ ├── assembly │ │ ├── bin.xml │ │ └── src.xml │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── functor │ │ ├── adapter │ │ ├── BinaryFunctionBinaryPredicate.java │ │ ├── BinaryFunctionBinaryProcedure.java │ │ ├── BinaryFunctionFunction.java │ │ ├── BinaryPredicateBinaryFunction.java │ │ ├── BinaryPredicatePredicate.java │ │ ├── BinaryProcedureBinaryFunction.java │ │ ├── BinaryProcedureProcedure.java │ │ ├── BoundNullaryFunction.java │ │ ├── BoundNullaryPredicate.java │ │ ├── BoundNullaryProcedure.java │ │ ├── FullyBoundNullaryFunction.java │ │ ├── FullyBoundNullaryPredicate.java │ │ ├── FullyBoundNullaryProcedure.java │ │ ├── FunctionPredicate.java │ │ ├── FunctionProcedure.java │ │ ├── IgnoreLeftFunction.java │ │ ├── IgnoreLeftPredicate.java │ │ ├── IgnoreLeftProcedure.java │ │ ├── IgnoreRightFunction.java │ │ ├── IgnoreRightPredicate.java │ │ ├── IgnoreRightProcedure.java │ │ ├── LeftBoundFunction.java │ │ ├── LeftBoundPredicate.java │ │ ├── LeftBoundProcedure.java │ │ ├── NullaryFunctionFunction.java │ │ ├── NullaryFunctionNullaryPredicate.java │ │ ├── NullaryFunctionNullaryProcedure.java │ │ ├── NullaryPredicateNullaryFunction.java │ │ ├── NullaryPredicatePredicate.java │ │ ├── NullaryProcedureNullaryFunction.java │ │ ├── NullaryProcedureProcedure.java │ │ ├── PredicateFunction.java │ │ ├── ProcedureFunction.java │ │ ├── RightBoundFunction.java │ │ ├── RightBoundPredicate.java │ │ ├── RightBoundProcedure.java │ │ └── package-info.java │ │ ├── aggregator │ │ ├── AbstractListBackedAggregator.java │ │ ├── AbstractNoStoreAggregator.java │ │ ├── AbstractTimedAggregator.java │ │ ├── Aggregator.java │ │ ├── ArrayListBackedAggregator.java │ │ ├── TimedAggregatorListener.java │ │ ├── functions │ │ │ ├── DoubleMaxAggregatorBinaryFunction.java │ │ │ ├── DoubleMaxAggregatorFunction.java │ │ │ ├── DoubleMeanValueAggregatorFunction.java │ │ │ ├── DoubleMedianValueAggregatorFunction.java │ │ │ ├── DoublePercentileAggregatorFunction.java │ │ │ ├── DoubleSumAggregatorBinaryFunction.java │ │ │ ├── DoubleSumAggregatorFunction.java │ │ │ ├── IntegerCountAggregatorBinaryFunction.java │ │ │ ├── IntegerMaxAggregatorBinaryFunction.java │ │ │ ├── IntegerMaxAggregatorFunction.java │ │ │ ├── IntegerMeanValueAggregatorFunction.java │ │ │ ├── IntegerMedianValueAggregatorFunction.java │ │ │ ├── IntegerPercentileAggregatorFunction.java │ │ │ ├── IntegerSumAggregatorBinaryFunction.java │ │ │ ├── IntegerSumAggregatorFunction.java │ │ │ └── package-info.java │ │ └── package-info.java │ │ ├── core │ │ ├── Constant.java │ │ ├── Identity.java │ │ ├── IsEqual.java │ │ ├── IsInstance.java │ │ ├── IsNotEqual.java │ │ ├── IsNotNull.java │ │ ├── IsNotSame.java │ │ ├── IsNull.java │ │ ├── IsSame.java │ │ ├── LeftIdentity.java │ │ ├── Limit.java │ │ ├── NoOp.java │ │ ├── Offset.java │ │ ├── RightIdentity.java │ │ ├── algorithm │ │ │ ├── DoUntil.java │ │ │ ├── DoWhile.java │ │ │ ├── FindWithinGenerator.java │ │ │ ├── FoldLeft.java │ │ │ ├── FoldRight.java │ │ │ ├── GeneratorContains.java │ │ │ ├── InPlaceTransform.java │ │ │ ├── IndexOfInGenerator.java │ │ │ ├── PredicatedLoop.java │ │ │ ├── RecursiveEvaluation.java │ │ │ ├── RemoveMatching.java │ │ │ ├── RetainMatching.java │ │ │ ├── UntilDo.java │ │ │ ├── WhileDo.java │ │ │ └── package-info.java │ │ ├── collection │ │ │ ├── FilteredIterable.java │ │ │ ├── FilteredIterator.java │ │ │ ├── IsElementOf.java │ │ │ ├── IsEmpty.java │ │ │ ├── Size.java │ │ │ ├── TransformedIterator.java │ │ │ └── package-info.java │ │ ├── comparator │ │ │ ├── ComparableComparator.java │ │ │ ├── ComparatorFunction.java │ │ │ ├── IsEquivalent.java │ │ │ ├── IsGreaterThan.java │ │ │ ├── IsGreaterThanOrEqual.java │ │ │ ├── IsLessThan.java │ │ │ ├── IsLessThanOrEqual.java │ │ │ ├── IsNotEquivalent.java │ │ │ ├── IsWithinRange.java │ │ │ ├── Max.java │ │ │ ├── Min.java │ │ │ └── package-info.java │ │ ├── composite │ │ │ ├── AbstractLoopNullaryProcedure.java │ │ │ ├── And.java │ │ │ ├── BaseBinaryPredicateList.java │ │ │ ├── BaseNullaryPredicateList.java │ │ │ ├── BasePredicateList.java │ │ │ ├── BinaryAnd.java │ │ │ ├── BinaryCompositeBinaryFunction.java │ │ │ ├── BinaryNot.java │ │ │ ├── BinaryOr.java │ │ │ ├── BinarySequence.java │ │ │ ├── Composite.java │ │ │ ├── CompositeBinaryFunction.java │ │ │ ├── CompositeBinaryPredicate.java │ │ │ ├── CompositeFunction.java │ │ │ ├── CompositePredicate.java │ │ │ ├── CompositeProcedure.java │ │ │ ├── Conditional.java │ │ │ ├── ConditionalBinaryFunction.java │ │ │ ├── ConditionalBinaryPredicate.java │ │ │ ├── ConditionalBinaryProcedure.java │ │ │ ├── ConditionalFunction.java │ │ │ ├── ConditionalNullaryFunction.java │ │ │ ├── ConditionalNullaryPredicate.java │ │ │ ├── ConditionalNullaryProcedure.java │ │ │ ├── ConditionalPredicate.java │ │ │ ├── ConditionalProcedure.java │ │ │ ├── DoWhileNullaryProcedure.java │ │ │ ├── Not.java │ │ │ ├── NullaryAnd.java │ │ │ ├── NullaryNot.java │ │ │ ├── NullaryOr.java │ │ │ ├── NullarySequence.java │ │ │ ├── Or.java │ │ │ ├── Sequence.java │ │ │ ├── TransformedBinaryFunction.java │ │ │ ├── TransformedBinaryProcedure.java │ │ │ ├── TransformedNullaryFunction.java │ │ │ ├── TransformedNullaryProcedure.java │ │ │ ├── TransposedFunction.java │ │ │ ├── TransposedPredicate.java │ │ │ ├── TransposedProcedure.java │ │ │ ├── WhileDoNullaryProcedure.java │ │ │ └── package-info.java │ │ └── package-info.java │ │ ├── generator │ │ ├── BaseGenerator.java │ │ ├── FilteredGenerator.java │ │ ├── Generator.java │ │ ├── loop │ │ │ ├── GenerateUntil.java │ │ │ ├── GenerateWhile.java │ │ │ ├── IteratorToGeneratorAdapter.java │ │ │ ├── LoopGenerator.java │ │ │ ├── TransformedGenerator.java │ │ │ ├── UntilGenerate.java │ │ │ ├── WhileGenerate.java │ │ │ └── package-info.java │ │ ├── package-info.java │ │ └── util │ │ │ ├── CollectionTransformer.java │ │ │ ├── EachElement.java │ │ │ └── package-info.java │ │ └── range │ │ ├── AbstractRange.java │ │ ├── BoundType.java │ │ ├── CharacterRange.java │ │ ├── DoubleRange.java │ │ ├── Endpoint.java │ │ ├── FloatRange.java │ │ ├── IntegerRange.java │ │ ├── LongRange.java │ │ ├── NumericRange.java │ │ ├── Range.java │ │ ├── Ranges.java │ │ └── package-info.java │ └── test │ ├── java │ └── org │ │ └── apache │ │ └── commons │ │ └── functor │ │ ├── BaseFunctorTest.java │ │ ├── TestAlgorithms.java │ │ ├── adapter │ │ ├── TestBinaryFunctionBinaryPredicate.java │ │ ├── TestBinaryFunctionBinaryProcedure.java │ │ ├── TestBinaryFunctionFunction.java │ │ ├── TestBinaryPredicateBinaryFunction.java │ │ ├── TestBinaryPredicatePredicate.java │ │ ├── TestBinaryProcedureBinaryFunction.java │ │ ├── TestBinaryProcedureProcedure.java │ │ ├── TestBoundNullaryFunction.java │ │ ├── TestBoundNullaryPredicate.java │ │ ├── TestBoundNullaryProcedure.java │ │ ├── TestFullyBoundNullaryFunction.java │ │ ├── TestFullyBoundNullaryPredicate.java │ │ ├── TestFullyBoundNullaryProcedure.java │ │ ├── TestFunctionPredicate.java │ │ ├── TestFunctionProcedure.java │ │ ├── TestIgnoreLeftFunction.java │ │ ├── TestIgnoreLeftPredicate.java │ │ ├── TestIgnoreLeftProcedure.java │ │ ├── TestIgnoreRightFunction.java │ │ ├── TestIgnoreRightPredicate.java │ │ ├── TestIgnoreRightProcedure.java │ │ ├── TestLeftBoundFunction.java │ │ ├── TestLeftBoundPredicate.java │ │ ├── TestLeftBoundProcedure.java │ │ ├── TestNullaryFunctionFunction.java │ │ ├── TestNullaryFunctionNullaryPredicate.java │ │ ├── TestNullaryFunctionNullaryProcedure.java │ │ ├── TestNullaryPredicateNullaryFunction.java │ │ ├── TestNullaryPredicatePredicate.java │ │ ├── TestNullaryProcedureNullaryFunction.java │ │ ├── TestPredicateFunction.java │ │ ├── TestProcedureFunction.java │ │ ├── TestProcedureProcedure.java │ │ ├── TestRightBoundFunction.java │ │ ├── TestRightBoundPredicate.java │ │ └── TestRightBoundProcedure.java │ │ ├── aggregator │ │ ├── AbstractListBackedAggregatorTest.java │ │ ├── AbstractNoStoreAggregatorTest.java │ │ ├── AbstractTimedAggregatorTest.java │ │ ├── ArrayListBackedAggregatorTest.java │ │ └── functions │ │ │ ├── DoubleMaxAggregatorBinaryFunctionTest.java │ │ │ ├── DoubleMaxAggregatorFunctionTest.java │ │ │ ├── DoubleMeanValueAggregatorFunctionTest.java │ │ │ ├── DoubleMedianValueAggregatorFunctionTest.java │ │ │ ├── DoublePercentileAggregatorFunctionTest.java │ │ │ ├── DoubleSumAggregatorBinaryFunctionTest.java │ │ │ ├── DoubleSumAggregatorFunctionTest.java │ │ │ ├── IntCountAggregatorBinaryFunctionTest.java │ │ │ ├── IntMaxAggregatorBinaryFunctionTest.java │ │ │ ├── IntMaxAggregatorFunctionTest.java │ │ │ ├── IntMeanValueAggregatorFunctionTest.java │ │ │ ├── IntMedianValueAggregatorFunctionTest.java │ │ │ ├── IntPercentileAggregatorFunctionTest.java │ │ │ ├── IntSumAggregatorBinaryFunctionTest.java │ │ │ └── IntSumAggregatorFunctionTest.java │ │ ├── core │ │ ├── TestConstant.java │ │ ├── TestIdentity.java │ │ ├── TestIsEqual.java │ │ ├── TestIsInstance.java │ │ ├── TestIsNotEqual.java │ │ ├── TestIsNotNull.java │ │ ├── TestIsNotSame.java │ │ ├── TestIsNull.java │ │ ├── TestIsSame.java │ │ ├── TestLeftIdentity.java │ │ ├── TestLimit.java │ │ ├── TestNoOp.java │ │ ├── TestOffset.java │ │ ├── TestRightIdentity.java │ │ ├── algorithm │ │ │ ├── TestDoUntil.java │ │ │ ├── TestDoWhile.java │ │ │ ├── TestFindWithinGenerator.java │ │ │ ├── TestFoldLeft.java │ │ │ ├── TestFoldRight.java │ │ │ ├── TestGeneratorContains.java │ │ │ ├── TestInPlaceTransform.java │ │ │ ├── TestIndexOfInGenerator.java │ │ │ ├── TestRecursiveEvaluation.java │ │ │ ├── TestRemoveMatching.java │ │ │ ├── TestRetainMatching.java │ │ │ ├── TestUntilDo.java │ │ │ └── TestWhileDo.java │ │ ├── collection │ │ │ ├── TestFilteredIterable.java │ │ │ ├── TestFilteredIterator.java │ │ │ ├── TestIsElementOf.java │ │ │ ├── TestIsEmpty.java │ │ │ ├── TestSize.java │ │ │ └── TestTransformedIterator.java │ │ ├── comparator │ │ │ ├── BaseComparisonPredicateTest.java │ │ │ ├── TestComparableComparator.java │ │ │ ├── TestComparatorFunction.java │ │ │ ├── TestIsEquivalent.java │ │ │ ├── TestIsGreaterThan.java │ │ │ ├── TestIsGreaterThanOrEqual.java │ │ │ ├── TestIsLessThan.java │ │ │ ├── TestIsLessThanOrEqual.java │ │ │ ├── TestIsNotEquivalent.java │ │ │ ├── TestIsWithinRange.java │ │ │ ├── TestMax.java │ │ │ └── TestMin.java │ │ └── composite │ │ │ ├── TestAbstractLoopNullaryProcedure.java │ │ │ ├── TestAnd.java │ │ │ ├── TestBinaryAnd.java │ │ │ ├── TestBinaryCompositeBinaryFunction.java │ │ │ ├── TestBinaryNot.java │ │ │ ├── TestBinaryOr.java │ │ │ ├── TestBinarySequence.java │ │ │ ├── TestComposite.java │ │ │ ├── TestCompositeBinaryFunction.java │ │ │ ├── TestCompositeBinaryPredicate.java │ │ │ ├── TestCompositeFunction.java │ │ │ ├── TestCompositePredicate.java │ │ │ ├── TestCompositeProcedure.java │ │ │ ├── TestConditional.java │ │ │ ├── TestConditionalBinaryFunction.java │ │ │ ├── TestConditionalBinaryPredicate.java │ │ │ ├── TestConditionalBinaryProcedure.java │ │ │ ├── TestConditionalFunction.java │ │ │ ├── TestConditionalNullaryFunction.java │ │ │ ├── TestConditionalNullaryPredicate.java │ │ │ ├── TestConditionalNullaryProcedure.java │ │ │ ├── TestConditionalPredicate.java │ │ │ ├── TestConditionalProcedure.java │ │ │ ├── TestDoWhileNullaryProcedure.java │ │ │ ├── TestNot.java │ │ │ ├── TestNullaryAnd.java │ │ │ ├── TestNullaryNot.java │ │ │ ├── TestNullaryOr.java │ │ │ ├── TestNullarySequence.java │ │ │ ├── TestOr.java │ │ │ ├── TestSequence.java │ │ │ ├── TestTransformedBinaryFunction.java │ │ │ ├── TestTransformedBinaryProcedure.java │ │ │ ├── TestTransformedNullaryFunction.java │ │ │ ├── TestTransformedNullaryProcedure.java │ │ │ ├── TestTransposedFunction.java │ │ │ ├── TestTransposedPredicate.java │ │ │ ├── TestTransposedProcedure.java │ │ │ └── TestWhileDoNullaryProcedure.java │ │ ├── example │ │ ├── FlexiMapExample.java │ │ ├── QuicksortExample.java │ │ ├── aggregator │ │ │ ├── list │ │ │ │ ├── OwnFunctionImplementationSample.java │ │ │ │ ├── OwnListImplementationSample.java │ │ │ │ └── package-info.java │ │ │ ├── nostore │ │ │ │ ├── AggregatedFunctionSample.java │ │ │ │ ├── NoStoreAggregatorSample.java │ │ │ │ └── package-info.java │ │ │ └── package-info.java │ │ ├── kata │ │ │ ├── four │ │ │ │ ├── Abs.java │ │ │ │ ├── DataMunger.java │ │ │ │ ├── IsInteger.java │ │ │ │ ├── NthColumn.java │ │ │ │ ├── TestSoccer.java │ │ │ │ ├── TestWeather.java │ │ │ │ └── ToInteger.java │ │ │ ├── one │ │ │ │ ├── Add.java │ │ │ │ ├── ArithmeticOperation.java │ │ │ │ ├── Divide.java │ │ │ │ ├── Mod.java │ │ │ │ ├── Money.java │ │ │ │ ├── Multiply.java │ │ │ │ ├── Product.java │ │ │ │ ├── Subtract.java │ │ │ │ ├── SupermarketPricingExample.java │ │ │ │ └── ToMoney.java │ │ │ └── two │ │ │ │ ├── BaseBinaryChop.java │ │ │ │ ├── BinaryChop.java │ │ │ │ ├── EiffelStyleLoop.java │ │ │ │ └── TestBinaryChop.java │ │ ├── lines │ │ │ ├── Contains.java │ │ │ ├── Count.java │ │ │ ├── Lines.java │ │ │ ├── StartsWith.java │ │ │ ├── Sum.java │ │ │ ├── TestAll.java │ │ │ ├── TestLines.java │ │ │ └── WordCount.java │ │ └── map │ │ │ ├── FixedSizeMap.java │ │ │ ├── FunctoredMap.java │ │ │ ├── LazyMap.java │ │ │ ├── PredicatedMap.java │ │ │ ├── TestAll.java │ │ │ ├── TestFixedSizeMap.java │ │ │ ├── TestLazyMap.java │ │ │ └── TestPredicatedMap.java │ │ ├── generator │ │ ├── TestBaseGenerator.java │ │ ├── TestFilteredGenerator.java │ │ ├── loop │ │ │ ├── TestGenerateUntil.java │ │ │ ├── TestGenerateWhile.java │ │ │ ├── TestIteratorToGeneratorAdapter.java │ │ │ ├── TestLoopGenerator.java │ │ │ ├── TestTransformedGenerator.java │ │ │ ├── TestUntilGenerate.java │ │ │ └── TestWhileGenerate.java │ │ └── util │ │ │ └── TestEachElement.java │ │ └── range │ │ ├── TestCharacterRange.java │ │ ├── TestDoubleRange.java │ │ ├── TestEndpoint.java │ │ ├── TestFloatRange.java │ │ ├── TestIntegerRange.java │ │ └── TestLongRange.java │ └── resources │ └── org │ └── apache │ └── commons │ └── functor │ └── example │ └── kata │ └── four │ ├── soccer.txt │ └── weather.txt ├── pom.xml └── src ├── changes └── changes.xml ├── conf ├── checkstyle.properties └── jdepend.properties └── site ├── resources ├── download_functor.cgi └── images │ ├── functor-logo-white.png │ └── functor-logo-white.xcf ├── site.xml └── xdoc ├── aggregator.xml ├── building.xml ├── download_functor.xml ├── examples.xml ├── index.xml ├── issue-tracking.xml └── mail-lists.xml /.asf.yaml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | github: 17 | description: "Apache Commons Functor (Dormant)" 18 | homepage: https://commons.apache.org/functor/ 19 | 20 | notifications: 21 | commits: commits@commons.apache.org 22 | issues: issues@commons.apache.org 23 | pullrequests: issues@commons.apache.org 24 | jira_options: link label 25 | jobs: notifications@commons.apache.org 26 | issues_bot_dependabot: notifications@commons.apache.org 27 | pullrequests_bot_dependabot: notifications@commons.apache.org 28 | issues_bot_codecov-commenter: notifications@commons.apache.org 29 | pullrequests_bot_codecov-commenter: notifications@commons.apache.org 30 | -------------------------------------------------------------------------------- /.github/GH-ROBOTS.txt: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # Keeps on creating FUD PRs in test code 17 | # Does not follow Apache disclosure policies 18 | User-agent: JLLeitschuh/security-research 19 | Disallow: * 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .project 3 | .classpath 4 | .settings/ 5 | .idea/ 6 | *.iml 7 | *.iws 8 | .DS_Store 9 | .vscode/ 10 | *.code-workspace 11 | .history/ 12 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 17 | The Apache code of conduct page is [https://www.apache.org/foundation/policies/conduct.html](https://www.apache.org/foundation/policies/conduct.html). 18 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | Apache Commons Functor 2 | Copyright 2003-2023, 2008-2023 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | -------------------------------------------------------------------------------- /RELEASE-NOTES.txt: -------------------------------------------------------------------------------- 1 | 17 | $Id$ 18 | 19 | 20 | Commons Functor Package 21 | Version 1.0 22 | Release Notes 23 | 24 | 25 | INTRODUCTION 26 | ============ 27 | 28 | This is the first Apache Commons Functor release. 29 | The Apache Commons Functor library defines common functor and functor-related interfaces, 30 | implementations, and utilities. 31 | 32 | IMPORTANT NOTES 33 | ================ 34 | 35 | BREAKING CHANGES: 36 | 37 | * NONE. 38 | 39 | DEPENDENCIES 40 | ============= 41 | 42 | * NONE. 43 | 44 | NEW FEATURES 45 | ============= 46 | 47 | * NONE. 48 | 49 | BUGS FROM PREVIOUS RELEASE 50 | =========================== 51 | 52 | * NONE. 53 | 54 | IMPROVEMENTS OVER PREVIOUS RELEASE 55 | =================================== 56 | 57 | * NONE. 58 | 59 | DEPRECATIONS 60 | ============ 61 | 62 | * NONE. 63 | 64 | OTHER NOTES 65 | ============ 66 | 67 | * NONE. 68 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 17 | The Apache Commons security page is [https://commons.apache.org/security.html](https://commons.apache.org/security.html). 18 | -------------------------------------------------------------------------------- /api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 4.0.0 20 | 21 | org.apache.commons 22 | commons-functor-parent 23 | 1.0-SNAPSHOT 24 | 25 | commons-functor-api 26 | Apache Commons Functor API 27 | Provide the basic APIs 28 | 29 | -------------------------------------------------------------------------------- /api/src/main/java/org/apache/commons/functor/BinaryFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor; 18 | 19 | /** 20 | * A functor that takes two arguments and returns a value. 21 | *

22 | * Implementors are encouraged but not required to make their functors 23 | * {@link java.io.Serializable Serializable}. 24 | *

25 | * @param the left argument type. 26 | * @param the right argument type. 27 | * @param the returned value type. 28 | * @since 1.0 29 | */ 30 | public interface BinaryFunction extends BinaryFunctor { 31 | /** 32 | * Evaluate this function. 33 | * 34 | * @param left the L element of the ordered pair of arguments 35 | * @param right the R element of the ordered pair of arguments 36 | * @return the T result of this function for the given arguments 37 | */ 38 | T evaluate(L left, R right); 39 | } 40 | -------------------------------------------------------------------------------- /api/src/main/java/org/apache/commons/functor/BinaryFunctor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor; 18 | 19 | /** 20 | * Marker interface for binary (two-argument) functors. 21 | *

22 | * Implementors are encouraged but not required to make their functors 23 | * {@link java.io.Serializable Serializable}. 24 | *

25 | * 26 | * @param the left argument type. 27 | * @param the right argument type. 28 | * @since 1.0 29 | */ 30 | public interface BinaryFunctor extends Functor { 31 | } 32 | -------------------------------------------------------------------------------- /api/src/main/java/org/apache/commons/functor/BinaryPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor; 18 | 19 | /** 20 | * A functor that takes two arguments and returns a boolean value. 21 | *

22 | * Implementors are encouraged but not required to make their functors 23 | * {@link java.io.Serializable Serializable}. 24 | *

25 | * 26 | * @param the left argument type. 27 | * @param the right argument type. 28 | * @since 1.0 29 | */ 30 | public interface BinaryPredicate extends BinaryFunctor { 31 | /** 32 | * Evaluate this predicate. 33 | * 34 | * @param left the L element of the ordered pair of arguments 35 | * @param right the R element of the ordered pair of arguments 36 | * @return the result of this test for the given arguments 37 | */ 38 | boolean test(L left, R right); 39 | } 40 | -------------------------------------------------------------------------------- /api/src/main/java/org/apache/commons/functor/BinaryProcedure.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor; 18 | 19 | /** 20 | * A functor that takes two arguments and has no return value. 21 | *

22 | * Implementors are encouraged but not required to make their functors 23 | * {@link java.io.Serializable Serializable}. 24 | *

25 | * 26 | * @param the left argument type. 27 | * @param the right argument type. 28 | * @since 1.0 29 | */ 30 | public interface BinaryProcedure extends BinaryFunctor { 31 | /** 32 | * Execute this procedure. 33 | * 34 | * @param left the L element of the ordered pair of arguments 35 | * @param right the R element of the ordered pair of arguments 36 | */ 37 | void run(L left, R right); 38 | } 39 | -------------------------------------------------------------------------------- /api/src/main/java/org/apache/commons/functor/Function.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor; 18 | 19 | /** 20 | * A functor that takes one argument and returns an Object value. 21 | *

22 | * Implementors are encouraged but not required to make their functors 23 | * {@link java.io.Serializable Serializable}. 24 | *

25 | * 26 | * @param the argument type. 27 | * @param the returned value type. 28 | * @since 1.0 29 | */ 30 | public interface Function extends UnaryFunctor { 31 | /** 32 | * Evaluate this function. 33 | * 34 | * @param obj the A object to evaluate 35 | * @return the T result of this evaluation 36 | */ 37 | T evaluate(A obj); 38 | } 39 | -------------------------------------------------------------------------------- /api/src/main/java/org/apache/commons/functor/Functor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor; 18 | 19 | /** 20 | * Functor marker interface. All provided functor interfaces extend this interface. 21 | *

22 | * While not strictly required, 23 | * it is encouraged that functor implementations: 24 | *

25 | *
    26 | *
  • Implement {@link java.io.Serializable Serializable}
  • 27 | *
  • Override {@link java.lang.Object#equals(java.lang.Object)}
  • 28 | *
  • Override {@link java.lang.Object#hashCode()}
  • 29 | *
  • Override {@link java.lang.Object#toString()}
  • 30 | *
31 | * 32 | * @since 1.0 33 | */ 34 | public interface Functor { 35 | } 36 | -------------------------------------------------------------------------------- /api/src/main/java/org/apache/commons/functor/NullaryFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor; 18 | 19 | /** 20 | * A functor that takes no arguments and returns a value. 21 | *

22 | * Implementors are encouraged but not required to make their functors 23 | * {@link java.io.Serializable Serializable}. 24 | *

25 | * 26 | * @param the returned value type. 27 | * @since 1.0 28 | */ 29 | public interface NullaryFunction extends NullaryFunctor { 30 | /** 31 | * Evaluate this function. 32 | * @return the T result of this evaluation 33 | */ 34 | T evaluate(); 35 | } 36 | -------------------------------------------------------------------------------- /api/src/main/java/org/apache/commons/functor/NullaryFunctor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor; 18 | 19 | /** 20 | * Marker interface for nullary (zero-argument) functors. 21 | *

22 | * Implementors are encouraged but not required to make their functors 23 | * {@link java.io.Serializable Serializable}. 24 | *

25 | * 26 | * @since 1.0 27 | */ 28 | public interface NullaryFunctor extends Functor { 29 | } 30 | -------------------------------------------------------------------------------- /api/src/main/java/org/apache/commons/functor/NullaryPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor; 18 | 19 | /** 20 | * A functor that takes no arguments and returns a boolean value. 21 | *

22 | * Implementors are encouraged but not required to make their functors 23 | * {@link java.io.Serializable Serializable}. 24 | *

25 | * 26 | * @since 1.0 27 | */ 28 | public interface NullaryPredicate extends NullaryFunctor { 29 | /** 30 | * Evaluate this predicate. 31 | * @return the result of this test 32 | */ 33 | boolean test(); 34 | } 35 | -------------------------------------------------------------------------------- /api/src/main/java/org/apache/commons/functor/NullaryProcedure.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor; 18 | 19 | /** 20 | * A functor that takes no arguments and returns no value. 21 | *

22 | * Note that this functor implements the 23 | * {@link Runnable Runnable} 24 | * interface, making all Procedures 25 | * immediately usable in a number of contexts (Swing, Jelly, etc.). 26 | *

27 | *

28 | * Implementors are encouraged but not required to make their functors 29 | * {@link java.io.Serializable Serializable}. 30 | *

31 | * 32 | * @since 1.0 33 | */ 34 | public interface NullaryProcedure extends NullaryFunctor, Runnable { 35 | /** Execute this procedure. */ 36 | void run(); 37 | } 38 | -------------------------------------------------------------------------------- /api/src/main/java/org/apache/commons/functor/Predicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor; 18 | 19 | /** 20 | * A functor that takes one argument and returns a boolean value. 21 | *

22 | * Implementors are encouraged but not required to make their functors 23 | * {@link java.io.Serializable Serializable}. 24 | *

25 | * 26 | * @param
the argument type. 27 | * @since 1.0 28 | */ 29 | public interface Predicate extends UnaryFunctor { 30 | /** 31 | * Evaluate this predicate. 32 | * 33 | * @param obj the A object to test 34 | * @return the result of this test 35 | */ 36 | boolean test(A obj); 37 | } 38 | -------------------------------------------------------------------------------- /api/src/main/java/org/apache/commons/functor/Procedure.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor; 18 | 19 | /** 20 | * A functor that takes one argument and returns no value. 21 | *

22 | * Implementors are encouraged but not required to make their functors 23 | * {@link java.io.Serializable Serializable}. 24 | *

25 | * 26 | * @param
the argument type. 27 | * @since 1.0 28 | */ 29 | public interface Procedure extends UnaryFunctor { 30 | /** 31 | * Execute this procedure. 32 | * @param obj an A parameter to this execution 33 | */ 34 | void run(A obj); 35 | } 36 | -------------------------------------------------------------------------------- /api/src/main/java/org/apache/commons/functor/UnaryFunctor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor; 18 | 19 | /** 20 | * Marker interface for unary (single-argument) functors. 21 | *

22 | * Implementors are encouraged but not required to make their functors 23 | * {@link java.io.Serializable Serializable}. 24 | *

25 | * 26 | * @param
the argument type. 27 | * @since 1.0 28 | */ 29 | public interface UnaryFunctor extends Functor { 30 | } 31 | -------------------------------------------------------------------------------- /api/src/main/java/org/apache/commons/functor/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | *

20 | * Basic functor interfaces. 21 | *

22 | *

23 | * Implementors are encouraged, but not strictly required, to make each functor 24 | * implementation {@link java.io.Serializable Serializable}. 25 | *

26 | *

27 | * Note that each functor interface extends the 28 | * {@link java.lang.Object#equals Object.equals} contract to state that 29 | * equals can return true only if 30 | * the specified Object implements the same functor interface 31 | * and is known to produce the same results and/or side-effects 32 | * for the same arguments (if any). Note that the default 33 | * Object.equals implementation 34 | * does in fact adhere to the functor equals contract. 35 | *

36 | */ 37 | package org.apache.commons.functor; 38 | -------------------------------------------------------------------------------- /build-tools/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 19 | org.apache.commons 20 | commons-functor-parent 21 | 1.0-SNAPSHOT 22 | 23 | 4.0.0 24 | commons-functor-build-tools 25 | Apache Commons Functor Build Tools 26 | Provide common setup, from http://maven.apache.org/plugins/maven-checkstyle-plugin/examples/multi-module-config.html 27 | 28 | -------------------------------------------------------------------------------- /build-tools/src/main/resources/org/apache/commons/functor/checkstyle-suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /build-tools/src/main/resources/org/apache/commons/functor/fb-excludes.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /build-tools/src/main/resources/org/apache/commons/functor/license-header.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ -------------------------------------------------------------------------------- /core/src/main/assembly/bin.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | bin 20 | 21 | tar.gz 22 | zip 23 | 24 | false 25 | 26 | 27 | 28 | LICENSE* 29 | NOTICE* 30 | RELEASE-NOTES.txt 31 | 32 | 33 | 34 | target 35 | 36 | 37 | *.jar 38 | 39 | 40 | 41 | target/site/apidocs 42 | apidocs 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /core/src/main/assembly/src.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | src 20 | 21 | tar.gz 22 | zip 23 | 24 | ${project.artifactId}-${project.version}-src 25 | 26 | 27 | 28 | LICENSE* 29 | NOTICE* 30 | pom.xml 31 | RELEASE-NOTES* 32 | 33 | 34 | 35 | src 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/adapter/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | *

20 | * Classes that adapt one functor interface to another. 21 | *

22 | */ 23 | package org.apache.commons.functor.adapter; 24 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/aggregator/Aggregator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.aggregator; 18 | 19 | import org.apache.commons.functor.NullaryFunction; 20 | 21 | /** 22 | * Interface which offers a means of "aggregating" data. It offers functions 23 | * which allows for data to be added to a "series" and then aggregate them. The 24 | * term "aggregation" is possibly a bit loose here as this interface doesn't 25 | * enforce summing up or averaging or any other way of processing the data -- it 26 | * simply allows for the values to be processed in such a way that it generates 27 | * a result. The aggregation of data will be done in the evaluate() 28 | * function. This is the function at the core of the aggregator package as it 29 | * allows for a way to process the data series and get a result of the same type 30 | * out of this operation. Note that some aggregators will compute the data at 31 | * this point by iterating through the series of data previously stored (if any) 32 | * while others might prefer to compute this value on the fly, every time 33 | * {@link #add(Object)} is called. This interface doesn't make any assumption as 34 | * to when the aggregation result should be computed. 35 | * 36 | * @param 37 | * type of data to aggregate 38 | */ 39 | public interface Aggregator extends NullaryFunction { 40 | /** 41 | * Adds data to the series which will be aggregated. It doesn't enforce any 42 | * limitations on how much data can be stored (or in fact whether it should 43 | * be stored) nor does it make any assumptions on synchronization. 44 | * 45 | * @param data 46 | * Data to be added to the series which this aggregator will 47 | * process/aggregate. 48 | */ 49 | void add(T data); 50 | 51 | /** 52 | * Resets any series of data previously stored and returns the aggregator in 53 | * the initial state. 54 | */ 55 | void reset(); 56 | } 57 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/aggregator/TimedAggregatorListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.aggregator; 18 | 19 | /** 20 | * Listener to be used with instances of {@link AbstractTimedAggregator} to 21 | * receive notifications when the timer kicks in. 22 | * 23 | * @param 24 | * Type of object the Aggregator is operating on. 25 | */ 26 | public interface TimedAggregatorListener { 27 | /** 28 | * Received when the aggregator listening to has triggered the timer. 29 | * 30 | * @param aggregator 31 | * Aggregator which has triggered the time event in the first 32 | * place. 33 | * @param evaluation 34 | * Current {@link AbstractTimedAggregator#evaluate() evaluation 35 | * result} of the aggregator which triggered the event 36 | */ 37 | void onTimer(AbstractTimedAggregator aggregator, T evaluation); 38 | } 39 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleMaxAggregatorBinaryFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.aggregator.functions; 18 | 19 | import org.apache.commons.functor.BinaryFunction; 20 | 21 | /** 22 | * Aggregation function to be used with subclasses of 23 | * {@link org.apache.commons.functor.aggregator.AbstractNoStoreAggregator} which 24 | * finds the maximum of 2 double(s). 25 | */ 26 | public final class DoubleMaxAggregatorBinaryFunction implements BinaryFunction { 27 | /** 28 | * Computes the maximum of the 2 given numbers and returns the result. 29 | * 30 | * @param left 31 | * first number to compare. If null, then 32 | * right will be returned. 33 | * @param right 34 | * second number to add. If null, then 35 | * left will be returned. 36 | * @return max of the 2 double's as described above 37 | */ 38 | public Double evaluate(Double left, Double right) { 39 | if (left == null) { 40 | return right; 41 | } 42 | if (right == null) { 43 | return left; 44 | } 45 | if (left.doubleValue() < right.doubleValue()) { 46 | return right; 47 | } 48 | return left; 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return DoubleMaxAggregatorBinaryFunction.class.getName(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleMaxAggregatorFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.aggregator.functions; 18 | 19 | import java.util.List; 20 | 21 | import org.apache.commons.functor.Function; 22 | 23 | /** 24 | * Aggregator function to be used with subclasses of 25 | * {@link org.apache.commons.functor.aggregator.AbstractListBackedAggregator} 26 | * which finds the maximum number in a list. It does this by traversing the list 27 | * (once) -- so the complexity of this will be O(n). 28 | */ 29 | public class DoubleMaxAggregatorFunction implements Function, Double> { 30 | /** 31 | * Does the actual traversal of the list and finds the maximum value then 32 | * returns the result. Please note that caller is responsible for 33 | * synchronizing access to the list. 34 | * 35 | * @param data 36 | * List to traverse and find max 37 | * @return max number in the list or null if the list is empty. 38 | */ 39 | public Double evaluate(List data) { 40 | if (data == null || data.size() == 0) { 41 | return null; 42 | } 43 | Double max = null; 44 | for (Double d : data) { 45 | if (max == null) { 46 | max = d; 47 | } else { 48 | if (max.doubleValue() < d.doubleValue()) { 49 | max = d; 50 | } 51 | } 52 | } 53 | return max; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return DoubleMaxAggregatorFunction.class.getName(); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleMeanValueAggregatorFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.aggregator.functions; 18 | 19 | import java.util.List; 20 | 21 | import org.apache.commons.functor.Function; 22 | 23 | /** 24 | * Aggregator function to be used with subclasses of 25 | * {@link org.apache.commons.functor.aggregator.AbstractListBackedAggregator} 26 | * which computes the arithmetic mean of all the numbers in the list. 27 | */ 28 | public final class DoubleMeanValueAggregatorFunction implements Function, Double> { 29 | /** 30 | * Does the actual computation and returns the result. Please note that 31 | * caller is responsible for synchronizing access to the list. 32 | * 33 | * @param data 34 | * List to traverse and sum 35 | * @return arithmetic mean (average) of all the data in the list or null if 36 | * the list is empty. 37 | */ 38 | public Double evaluate(List data) { 39 | if (data == null || data.size() == 0) { 40 | return null; 41 | } 42 | double mean = 0.0; 43 | int n = data.size(); 44 | for (Double d : data) { 45 | mean += d.doubleValue(); 46 | } 47 | mean /= n; 48 | 49 | return mean; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return DoubleMeanValueAggregatorFunction.class.getName(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleSumAggregatorBinaryFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.aggregator.functions; 18 | 19 | import org.apache.commons.functor.BinaryFunction; 20 | 21 | /** 22 | * Aggregator function to be used with subclasses of 23 | * {@link org.apache.commons.functor.aggregator.AbstractNoStoreAggregator} which 24 | * sums up the 2 given numbers (hence the "Binary" in the name!). Counterpart of 25 | * {@link DoubleSumAggregatorFunction}. 26 | */ 27 | public final class DoubleSumAggregatorBinaryFunction implements BinaryFunction { 28 | /** 29 | * Adds the 2 numbers together and returns the result. 30 | * 31 | * @param left 32 | * first number to add. If null, then 33 | * right will be returned. 34 | * @param right 35 | * second number to add. If null, then 36 | * left will be returned. 37 | * @return sum of the 2 double's as described above 38 | */ 39 | public Double evaluate(Double left, Double right) { 40 | if (left == null) { 41 | return right; 42 | } 43 | if (right == null) { 44 | return left; 45 | } 46 | return left + right; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return DoubleSumAggregatorBinaryFunction.class.getName(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleSumAggregatorFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.aggregator.functions; 18 | 19 | import java.util.List; 20 | 21 | import org.apache.commons.functor.Function; 22 | 23 | /** 24 | * Aggregator function to be used with subclasses of 25 | * {@link org.apache.commons.functor.aggregator.AbstractListBackedAggregator} 26 | * which sums up all the numbers in the list. 27 | */ 28 | public final class DoubleSumAggregatorFunction implements Function, Double> { 29 | /** 30 | * Does the actual adding and returns the result. Please note that caller is 31 | * responsible for synchronizing access to the list. 32 | * 33 | * @param data 34 | * List to traverse and sum 35 | * @return arithmetic sum of all the data in the list or null if the list is 36 | * empty. 37 | */ 38 | public Double evaluate(List data) { 39 | if (data == null || data.size() == 0) { 40 | return null; 41 | } 42 | double sum = 0.0; 43 | for (Double d : data) { 44 | sum += d; 45 | } 46 | return sum; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return DoubleSumAggregatorFunction.class.getName(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerMaxAggregatorBinaryFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.aggregator.functions; 18 | 19 | import org.apache.commons.functor.BinaryFunction; 20 | 21 | /** 22 | * Aggregation function to be used with subclasses of 23 | * {@link org.apache.commons.functor.aggregator.AbstractNoStoreAggregator} which 24 | * finds the maximum of 2 ints. 25 | */ 26 | public class IntegerMaxAggregatorBinaryFunction implements BinaryFunction { 27 | /** 28 | * Computes the maximum of the 2 given numbers and returns the result. 29 | * 30 | * @param left 31 | * first number to compare. If null, then 32 | * right will be returned. 33 | * @param right 34 | * second number to add. If null, then 35 | * left will be returned. 36 | * @return max of the 2 integers as described above 37 | */ 38 | public Integer evaluate(Integer left, Integer right) { 39 | if (left == null) { 40 | return right; 41 | } 42 | if (right == null) { 43 | return left; 44 | } 45 | if (left.intValue() < right.intValue()) { 46 | return right; 47 | } 48 | return left; 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return IntegerMaxAggregatorBinaryFunction.class.getName(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerMaxAggregatorFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.aggregator.functions; 18 | 19 | import java.util.List; 20 | 21 | import org.apache.commons.functor.Function; 22 | 23 | /** 24 | * Aggregator function to be used with subclasses of 25 | * {@link org.apache.commons.functor.aggregator.AbstractListBackedAggregator} 26 | * which finds the maximum number in a list. It does this by traversing the list 27 | * (once) -- so the complexity of this will be O(n). 28 | */ 29 | public class IntegerMaxAggregatorFunction implements Function, Integer> { 30 | /** 31 | * Does the actual traversal of the list and finds the maximum value then 32 | * returns the result. Please note that caller is responsible for 33 | * synchronizing access to the list. 34 | * 35 | * @param data 36 | * List to traverse and find max 37 | * @return max number in the list or null if the list is empty. 38 | */ 39 | public Integer evaluate(List data) { 40 | if (data == null || data.size() == 0) { 41 | return null; 42 | } 43 | Integer max = null; 44 | for (Integer d : data) { 45 | if (max == null) { 46 | max = d; 47 | } else { 48 | if (max.intValue() < d.intValue()) { 49 | max = d; 50 | } 51 | } 52 | } 53 | return max; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return IntegerMaxAggregatorFunction.class.getName(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerMeanValueAggregatorFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.aggregator.functions; 18 | 19 | import java.util.List; 20 | 21 | import org.apache.commons.functor.Function; 22 | 23 | /** 24 | * Aggregator function to be used with subclasses of 25 | * {@link org.apache.commons.functor.aggregator.AbstractListBackedAggregator} 26 | * which computes the arithmetic mean of all the numbers in the list. 27 | */ 28 | public final class IntegerMeanValueAggregatorFunction implements Function, Integer> { 29 | /** 30 | * Does the actual computation and returns the result. Please note that 31 | * caller is responsible for synchronizing access to the list. 32 | * 33 | * @param data 34 | * List to traverse and sum 35 | * @return arithmetic mean (average) of all the data in the list or null if 36 | * the list is empty. 37 | */ 38 | public Integer evaluate(List data) { 39 | if (data == null || data.size() == 0) { 40 | return null; 41 | } 42 | int mean = 0; 43 | int n = data.size(); 44 | for (Integer d : data) { 45 | mean += d.intValue(); 46 | } 47 | mean /= n; 48 | 49 | return mean; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return IntegerMeanValueAggregatorFunction.class.getName(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerSumAggregatorBinaryFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.aggregator.functions; 18 | 19 | import org.apache.commons.functor.BinaryFunction; 20 | 21 | /** 22 | * Aggregator function to be used with subclasses of 23 | * {@link org.apache.commons.functor.aggregator.AbstractNoStoreAggregator} which 24 | * sums up the 2 given numbers (hence the "Binary" in the name!). Counterpart of 25 | * {@link IntegerSumAggregatorFunction}. 26 | */ 27 | public final class IntegerSumAggregatorBinaryFunction implements BinaryFunction { 28 | /** 29 | * Adds the 2 numbers together and returns the result. 30 | * 31 | * @param left 32 | * first number to add. If null, then 33 | * right will be returned. 34 | * @param right 35 | * second number to add. If null, then 36 | * left will be returned. 37 | * @return sum of the 2 int's as described above 38 | */ 39 | public Integer evaluate(Integer left, Integer right) { 40 | if (left == null) { 41 | return right; 42 | } 43 | if (right == null) { 44 | return left; 45 | } 46 | return left + right; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return IntegerSumAggregatorBinaryFunction.class.getName(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerSumAggregatorFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.aggregator.functions; 18 | 19 | import java.util.List; 20 | 21 | import org.apache.commons.functor.Function; 22 | 23 | /** 24 | * Aggregator function to be used with subclasses of 25 | * {@link org.apache.commons.functor.aggregator.AbstractListBackedAggregator} 26 | * which sums up all the numbers in the list. 27 | */ 28 | public final class IntegerSumAggregatorFunction implements Function, Integer> { 29 | /** 30 | * Does the actual adding and returns the result. Please note that caller is 31 | * responsible for synchronizing access to the list. 32 | * 33 | * @param data 34 | * List to traverse and sum 35 | * @return arithmetic sum of all the data in the list or null if the list is 36 | * empty. 37 | */ 38 | public Integer evaluate(List data) { 39 | if (data == null || data.size() == 0) { 40 | return null; 41 | } 42 | int sum = 0; 43 | for (Integer d : data) { 44 | sum += d; 45 | } 46 | return sum; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return IntegerSumAggregatorFunction.class.getName(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/aggregator/functions/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | *

20 | * This package contains Function's used by aggregators 21 | * defined in org.apache.commons.functor.aggregator. 22 | *

23 | *

24 | * These will normally be passed as parameters in constructors to classes 25 | * such as {@link org.apache.commons.functor.aggregator.AbstractListBackedAggregator} 26 | * to allow for customization of aggregation services. 27 | *

28 | */ 29 | package org.apache.commons.functor.aggregator.functions; 30 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/aggregator/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | *

20 | * This package contains the interfaces and utilities needed to implement 21 | * an aggregation service. 22 | *

23 | *

24 | * Aggregation refers to being able to add data to a data "sink" which 25 | * "aggregates" them automatically (e.g. sum them up or average, median etc). 26 | *

27 | *

28 | * An example of an aggregation service is being able to average a series 29 | * of int values (perhaps generated from a monitoring component) 30 | * and be able to constantly report on the average (or mean) value of 31 | * this series. There is no specification about the maximum amount of data that 32 | * can be aggregated -- some subclasses might impose such restrictions, 33 | * if that is the case then that will be specified in their Javadoc's. 34 | *

35 | */ 36 | package org.apache.commons.functor.aggregator; 37 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/core/algorithm/DoUntil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.core.algorithm; 18 | 19 | import org.apache.commons.functor.NullaryPredicate; 20 | import org.apache.commons.functor.NullaryProcedure; 21 | 22 | /** 23 | * Do-until algorithm (test after). 24 | */ 25 | public class DoUntil extends PredicatedLoop { 26 | 27 | /** 28 | * Create a new DoUntil. 29 | * @param body to execute 30 | * @param test whether to keep going 31 | */ 32 | public DoUntil(NullaryProcedure body, NullaryPredicate test) { 33 | super(body, test); 34 | } 35 | 36 | /** 37 | * {@inheritDoc} 38 | */ 39 | public final void run() { 40 | do { 41 | getBody().run(); 42 | } while (!getTest().test()); 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | */ 48 | @Override 49 | public String toString() { 50 | return "DoUntil<" + getBody() + "," + getTest() + ">"; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/core/algorithm/DoWhile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.core.algorithm; 18 | 19 | import org.apache.commons.functor.NullaryPredicate; 20 | import org.apache.commons.functor.NullaryProcedure; 21 | 22 | /** 23 | * Do-while algorithm (test after). 24 | */ 25 | public class DoWhile extends PredicatedLoop { 26 | 27 | /** 28 | * Create a new DoWhile. 29 | * @param body to execute 30 | * @param test whether to keep going 31 | */ 32 | public DoWhile(NullaryProcedure body, NullaryPredicate test) { 33 | super(body, test); 34 | } 35 | 36 | /** 37 | * {@inheritDoc} 38 | */ 39 | public final void run() { 40 | do { 41 | getBody().run(); 42 | } while (getTest().test()); 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | */ 48 | @Override 49 | public String toString() { 50 | return "DoWhile<" + getBody() + "," + getTest() + ">"; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/core/algorithm/InPlaceTransform.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.core.algorithm; 18 | 19 | import java.util.ListIterator; 20 | 21 | import org.apache.commons.functor.BinaryProcedure; 22 | import org.apache.commons.functor.Function; 23 | 24 | /** 25 | * Implements an in-place transformation of a ListIterator's contents. 26 | * 27 | * @param the arguments type 28 | */ 29 | public final class InPlaceTransform 30 | implements BinaryProcedure, Function> { 31 | /** 32 | * A static {@code InPlaceTransform} instance reference. 33 | */ 34 | private static final InPlaceTransform INSTANCE = new InPlaceTransform(); 35 | 36 | /** 37 | * {@inheritDoc} 38 | * @param left {@link ListIterator} 39 | * @param right {@link Function} 40 | */ 41 | public void run(ListIterator left, Function right) { 42 | while (left.hasNext()) { 43 | left.set(right.evaluate(left.next())); 44 | } 45 | } 46 | 47 | /** 48 | * {@inheritDoc} 49 | */ 50 | @Override 51 | public boolean equals(Object obj) { 52 | return obj == this || obj != null && obj.getClass().equals(getClass()); 53 | } 54 | 55 | /** 56 | * {@inheritDoc} 57 | */ 58 | @Override 59 | public int hashCode() { 60 | return System.identityHashCode(INSTANCE); 61 | } 62 | 63 | /** 64 | * {@inheritDoc} 65 | */ 66 | @Override 67 | public String toString() { 68 | return "InPlaceTransform"; 69 | } 70 | 71 | /** 72 | * Get an {@link InPlaceTransform} instance. 73 | * @return InPlaceTransform 74 | */ 75 | public static InPlaceTransform instance() { 76 | return INSTANCE; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/core/algorithm/RemoveMatching.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.core.algorithm; 18 | 19 | import java.util.Iterator; 20 | 21 | import org.apache.commons.functor.BinaryProcedure; 22 | import org.apache.commons.functor.Predicate; 23 | 24 | /** 25 | * Remove elements from left Iterator that match right Predicate. 26 | * 27 | * @param the procedure argument type. 28 | */ 29 | public final class RemoveMatching 30 | implements BinaryProcedure, Predicate> { 31 | /** 32 | * A static {@link RemoveMatching} instance reference. 33 | */ 34 | private static final RemoveMatching INSTANCE = new RemoveMatching(); 35 | 36 | /** 37 | * {@inheritDoc} 38 | * @param left {@link Iterator} 39 | * @param right {@link Predicate} 40 | */ 41 | public void run(Iterator left, Predicate right) { 42 | while (left.hasNext()) { 43 | if (right.test(left.next())) { 44 | left.remove(); 45 | } 46 | } 47 | } 48 | 49 | /** 50 | * {@inheritDoc} 51 | */ 52 | @Override 53 | public boolean equals(Object obj) { 54 | return obj == this || obj != null && obj.getClass().equals(getClass()); 55 | } 56 | 57 | /** 58 | * {@inheritDoc} 59 | */ 60 | @Override 61 | public int hashCode() { 62 | return System.identityHashCode(INSTANCE); 63 | } 64 | 65 | /** 66 | * {@inheritDoc} 67 | */ 68 | @Override 69 | public String toString() { 70 | return "RemoveMatching"; 71 | } 72 | 73 | /** 74 | * Get a static {@link RemoveMatching} instance. 75 | * @return {@link RemoveMatching} 76 | */ 77 | public static RemoveMatching instance() { 78 | return INSTANCE; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/core/algorithm/RetainMatching.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.core.algorithm; 18 | 19 | import java.util.Iterator; 20 | 21 | import org.apache.commons.functor.BinaryProcedure; 22 | import org.apache.commons.functor.Predicate; 23 | import org.apache.commons.functor.core.composite.Not; 24 | 25 | /** 26 | * Retain elements in left Iterator that match right Predicate. 27 | * 28 | * @param the procedure argument type 29 | */ 30 | public final class RetainMatching 31 | implements BinaryProcedure, Predicate> { 32 | /** 33 | * A static {@code RetainMatching} instance reference. 34 | */ 35 | private static final RetainMatching INSTANCE = new RetainMatching(); 36 | /** 37 | * The {@code RemoveMatching} instance used to remove elements from input iterator. 38 | */ 39 | private final RemoveMatching removeMatching = new RemoveMatching(); 40 | 41 | /** 42 | * {@inheritDoc} 43 | * @param left {@link Iterator} 44 | * @param right {@link Predicate} 45 | */ 46 | public void run(Iterator left, Predicate right) { 47 | removeMatching.run(left, Not.not(right)); 48 | } 49 | 50 | /** 51 | * {@inheritDoc} 52 | */ 53 | @Override 54 | public boolean equals(Object obj) { 55 | return obj == this || obj != null && obj.getClass().equals(getClass()); 56 | } 57 | 58 | /** 59 | * {@inheritDoc} 60 | */ 61 | @Override 62 | public int hashCode() { 63 | return System.identityHashCode(INSTANCE); 64 | } 65 | 66 | /** 67 | * {@inheritDoc} 68 | */ 69 | @Override 70 | public String toString() { 71 | return "RetainMatching"; 72 | } 73 | 74 | /** 75 | * Get a static {@link RetainMatching} instance. 76 | * @return {@link RetainMatching} 77 | */ 78 | public static RetainMatching instance() { 79 | return INSTANCE; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/core/algorithm/UntilDo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.core.algorithm; 18 | 19 | import org.apache.commons.functor.NullaryPredicate; 20 | import org.apache.commons.functor.NullaryProcedure; 21 | 22 | /** 23 | * Until-do algorithm (test before). 24 | */ 25 | public class UntilDo extends PredicatedLoop { 26 | 27 | /** 28 | * Create a new UntilDo. 29 | * @param test whether to keep going 30 | * @param body to execute 31 | */ 32 | public UntilDo(NullaryPredicate test, NullaryProcedure body) { 33 | super(body, test); 34 | } 35 | 36 | /** 37 | * {@inheritDoc} 38 | */ 39 | public final void run() { 40 | while (!getTest().test()) { 41 | getBody().run(); 42 | } 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | */ 48 | @Override 49 | public String toString() { 50 | return "UntilDo<" + getTest() + "," + getBody() + ">"; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/core/algorithm/WhileDo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.core.algorithm; 18 | 19 | import org.apache.commons.functor.NullaryPredicate; 20 | import org.apache.commons.functor.NullaryProcedure; 21 | 22 | /** 23 | * While-do algorithm (test before). 24 | */ 25 | public class WhileDo extends PredicatedLoop { 26 | 27 | /** 28 | * Create a new WhileDo. 29 | * @param test whether to keep going 30 | * @param body to execute 31 | */ 32 | public WhileDo(NullaryPredicate test, NullaryProcedure body) { 33 | super(body, test); 34 | } 35 | 36 | /** 37 | * {@inheritDoc} 38 | */ 39 | public final void run() { 40 | while (getTest().test()) { 41 | getBody().run(); 42 | } 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | */ 48 | @Override 49 | public String toString() { 50 | return "WhileDo<" + getTest() + "," + getBody() + ">"; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/core/algorithm/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | *

20 | * Various algorithm-esque functors. 21 | *

22 | */ 23 | package org.apache.commons.functor.core.algorithm; 24 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/core/collection/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | *

20 | * {@link java.util.Collection Collection}-based functors, algorithms and utilities. 21 | *

22 | */ 23 | package org.apache.commons.functor.core.collection; 24 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/core/comparator/ComparableComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.core.comparator; 18 | 19 | import java.util.Comparator; 20 | 21 | /** 22 | * A {@link Comparator Comparator} that compares {@link Comparable Comparable} 23 | * objects. 24 | *

25 | * This class was created based on commons-collection's ComparableComparator. 26 | * 27 | * @param the comparable type 28 | */ 29 | final class ComparableComparator> implements Comparator { 30 | 31 | /** Singleton. */ 32 | @SuppressWarnings("rawtypes") 33 | public static final ComparableComparator INSTANCE = new ComparableComparator(); 34 | 35 | /** 36 | * Create a new ComparableComparator. 37 | */ 38 | public ComparableComparator() { 39 | super(); 40 | } 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | public int compare(E o1, E o2) { 46 | return o1.compareTo(o2); 47 | } 48 | 49 | /** 50 | * {@inheritDoc} 51 | */ 52 | @Override 53 | public boolean equals(Object obj) { 54 | return (obj instanceof ComparableComparator); 55 | } 56 | 57 | /** 58 | * {@inheritDoc} 59 | */ 60 | @Override 61 | public int hashCode() { 62 | return toString().hashCode(); 63 | } 64 | 65 | /** 66 | * {@inheritDoc} 67 | */ 68 | @Override 69 | public String toString() { 70 | return "ComparableComparator"; 71 | } 72 | 73 | /** 74 | * Get a ComparableComparator instance. 75 | * @param the comparable type 76 | * @return ComparableComparator 77 | */ 78 | @SuppressWarnings("unchecked") 79 | public static > ComparableComparator instance() { 80 | return (ComparableComparator) INSTANCE; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/core/comparator/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | *

20 | * {@link java.util.Comparator Comparator}- and 21 | * {@link java.lang.Comparable Comparable}-based functors, algorithms and utilities. 22 | *

23 | */ 24 | package org.apache.commons.functor.core.comparator; 25 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/core/composite/DoWhileNullaryProcedure.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.core.composite; 18 | 19 | import org.apache.commons.functor.NullaryPredicate; 20 | import org.apache.commons.functor.NullaryProcedure; 21 | 22 | /** 23 | * A {@link NullaryProcedure} implementation of a while loop. Given a {@link NullaryPredicate} 24 | * c and an {@link NullaryProcedure} p, {@link #run runs} 25 | * do { p.run(); } while(c.test()). 26 | */ 27 | public class DoWhileNullaryProcedure extends AbstractLoopNullaryProcedure { 28 | 29 | /** 30 | * Create a new DoWhileNullaryProcedure. 31 | * @param action to do 32 | * @param condition while true 33 | */ 34 | public DoWhileNullaryProcedure(NullaryProcedure action, NullaryPredicate condition) { 35 | super(condition, action); 36 | } 37 | 38 | /** 39 | * {@inheritDoc} 40 | */ 41 | public final void run() { 42 | do { 43 | getAction().run(); 44 | } while (getCondition().test()); 45 | } 46 | 47 | /** 48 | * {@inheritDoc} 49 | */ 50 | @Override 51 | public String toString() { 52 | return "DoWhileNullaryProcedure"; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/core/composite/WhileDoNullaryProcedure.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.core.composite; 18 | 19 | import org.apache.commons.functor.NullaryPredicate; 20 | import org.apache.commons.functor.NullaryProcedure; 21 | 22 | /** 23 | * A {@link NullaryProcedure} implementation of a while loop. Given a {@link NullaryPredicate} 24 | * c and an {@link NullaryProcedure} p, {@link #run runs} 25 | * while(c.test()) { p.run(); }. 26 | */ 27 | public class WhileDoNullaryProcedure extends AbstractLoopNullaryProcedure { 28 | /** 29 | * Create a new WhileDoNullaryProcedure. 30 | * @param condition while 31 | * @param action to do 32 | */ 33 | public WhileDoNullaryProcedure(NullaryPredicate condition, NullaryProcedure action) { 34 | super(condition, action); 35 | } 36 | 37 | /** 38 | * {@inheritDoc} 39 | */ 40 | public void run() { 41 | while (getCondition().test()) { 42 | getAction().run(); 43 | } 44 | } 45 | 46 | /** 47 | * {@inheritDoc} 48 | */ 49 | @Override 50 | public String toString() { 51 | return "WhileDoNullaryProcedure"; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/core/composite/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | *

20 | * Functors composed of other functors. 21 | *

22 | */ 23 | package org.apache.commons.functor.core.composite; 24 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/core/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | *

20 | * Commonly used functor implementations. 21 | *

22 | */ 23 | package org.apache.commons.functor.core; 24 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/generator/BaseGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package org.apache.commons.functor.generator; 16 | 17 | import java.util.Collection; 18 | 19 | import org.apache.commons.functor.Function; 20 | import org.apache.commons.functor.generator.util.CollectionTransformer; 21 | 22 | /** 23 | * Base class for generators. Adds support for all of the Algorithms to 24 | * each subclass. 25 | * 26 | * @param the type of elements held in this generator. 27 | * @since 1.0 28 | */ 29 | public abstract class BaseGenerator implements Generator { 30 | 31 | /** Create a new generator. */ 32 | public BaseGenerator() { 33 | super(); 34 | } 35 | 36 | /** 37 | * {@inheritDoc} 38 | * Transforms this generator using the passed in 39 | * Function. An example function might turn the contents of the 40 | * generator into a {@link Collection} of elements. 41 | */ 42 | public final T to(Function, ? extends T> transformer) { 43 | return transformer.evaluate(this); 44 | } 45 | 46 | /** 47 | * {@inheritDoc} 48 | * Same as to(new CollectionTransformer(collection)). 49 | */ 50 | public final > C to(C collection) { 51 | return to(new CollectionTransformer(collection)); 52 | } 53 | 54 | /** 55 | * {@inheritDoc} 56 | * Same as to(new CollectionTransformer()). 57 | */ 58 | public final Collection toCollection() { 59 | return to(CollectionTransformer. toCollection()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/generator/Generator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package org.apache.commons.functor.generator; 15 | 16 | import java.util.Collection; 17 | 18 | import org.apache.commons.functor.Function; 19 | import org.apache.commons.functor.Procedure; 20 | 21 | /** 22 | * The Generator interface defines a number of useful actions applying Procedures 23 | * to each in a series of argument Objects. 24 | * 25 | * @param the type of elements held in this generator. 26 | */ 27 | public interface Generator { 28 | /** 29 | * Generators must implement this method. 30 | * @param proc Procedure to run 31 | */ 32 | void run(Procedure proc); 33 | 34 | /** 35 | * Transforms this generator using the passed in 36 | * transformer. An example transformer might turn the contents of the 37 | * generator into a {@link Collection} of elements. 38 | * @param the returned value type of the input {@link Function} 39 | * @param transformer Function to apply to this 40 | * @return transformation result 41 | */ 42 | Z to(Function, ? extends Z> transformer); 43 | 44 | /** 45 | * Same as to(new CollectionTransformer(collection)). 46 | * @param the returned collection type 47 | * @param collection Collection to which my elements should be added 48 | * @return collection 49 | */ 50 | > C to(C collection); 51 | 52 | /** 53 | * Same as to(new CollectionTransformer()). 54 | * @return Collection 55 | */ 56 | Collection toCollection(); 57 | } 58 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/generator/loop/LoopGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package org.apache.commons.functor.generator.loop; 16 | 17 | import org.apache.commons.functor.generator.BaseGenerator; 18 | import org.apache.commons.functor.generator.Generator; 19 | 20 | /** 21 | * Base class for generators that control execution flow, and may need to 22 | * stop the generation. 23 | * 24 | * @param the type of elements held in this generator. 25 | * @since 1.0 26 | */ 27 | public abstract class LoopGenerator extends BaseGenerator { 28 | 29 | /** A generator can wrap another generator. */ 30 | private final Generator wrappedGenerator; 31 | 32 | /** Set to true when the generator is {@link #stop stopped}. */ 33 | private boolean stopped = false; 34 | 35 | /** Create a new generator. */ 36 | public LoopGenerator() { 37 | this(null); 38 | } 39 | 40 | /** 41 | * A generator can wrap another generator. When wrapping generators you 42 | * should use probably this constructor since doing so will cause the 43 | * {@link #stop} method to stop the wrapped generator as well. 44 | * @param generator Generator to wrap 45 | */ 46 | public LoopGenerator(Generator generator) { 47 | this.wrappedGenerator = generator; 48 | } 49 | 50 | /** 51 | * Get the generator that is being wrapped. 52 | * @return Generator 53 | */ 54 | protected Generator getWrappedGenerator() { 55 | return wrappedGenerator; 56 | } 57 | 58 | /** 59 | * Stop the generator. Will stop the wrapped generator if one was set. 60 | */ 61 | public void stop() { 62 | if (wrappedGenerator != null && wrappedGenerator instanceof LoopGenerator) { 63 | ((LoopGenerator) wrappedGenerator).stop(); 64 | } 65 | stopped = true; 66 | } 67 | 68 | /** 69 | * Check if the generator is stopped. 70 | * @return true if the generator is stopped, false 71 | * otherwise 72 | */ 73 | public boolean isStopped() { 74 | return stopped; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/generator/loop/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | /** 15 | *

16 | * Contains code related to Generators that control execution flow. 17 | *

18 | */ 19 | package org.apache.commons.functor.generator.loop; 20 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/generator/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | *

20 | * Contains code related to Generators. 21 | *

22 | */ 23 | package org.apache.commons.functor.generator; 24 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/generator/util/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | *

20 | * Contains utility code for Generators. 21 | *

22 | */ 23 | package org.apache.commons.functor.generator.util; 24 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/range/BoundType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.range; 18 | 19 | /** 20 | * Determine the bound type of a range. 21 | * 22 | * @see org.apache.commons.functor.range.Range 23 | * @see org.apache.commons.functor.range.Endpoint 24 | * @since 1.0 25 | */ 26 | public enum BoundType { 27 | // values 28 | // --------------------------------------------------------------- 29 | /** 30 | * Represents an open bound, which value is not included in 31 | * the range. 32 | */ 33 | OPEN, 34 | /** 35 | * Represents a closed bound, which value is included in the 36 | * range. 37 | */ 38 | CLOSED; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /core/src/main/java/org/apache/commons/functor/range/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | *

20 | * Contains code related to Ranges. 21 | *

22 | */ 23 | package org.apache.commons.functor.range; 24 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/adapter/TestBinaryProcedureProcedure.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.adapter; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertNotNull; 21 | import static org.junit.Assert.assertNull; 22 | import static org.junit.Assert.assertTrue; 23 | 24 | import org.apache.commons.functor.BaseFunctorTest; 25 | import org.apache.commons.functor.Procedure; 26 | import org.apache.commons.functor.core.NoOp; 27 | import org.junit.Test; 28 | 29 | /** 30 | */ 31 | public class TestBinaryProcedureProcedure extends BaseFunctorTest { 32 | 33 | // Functor Testing Framework 34 | // ------------------------------------------------------------------------ 35 | 36 | @Override 37 | protected Object makeFunctor() { 38 | return new BinaryProcedureProcedure(NoOp.INSTANCE); 39 | } 40 | 41 | // Tests 42 | // ------------------------------------------------------------------------ 43 | 44 | @Test 45 | public void testRun() throws Exception { 46 | Procedure p = new BinaryProcedureProcedure(NoOp.INSTANCE); 47 | p.run(null); 48 | } 49 | 50 | @Test 51 | public void testEquals() throws Exception { 52 | Procedure p = new BinaryProcedureProcedure(NoOp.INSTANCE); 53 | assertEquals(p, p); 54 | assertObjectsAreEqual(p, new BinaryProcedureProcedure(NoOp.INSTANCE)); 55 | assertObjectsAreNotEqual(p, NoOp.INSTANCE); 56 | assertObjectsAreNotEqual(p, new BinaryProcedureProcedure(IgnoreLeftProcedure.adapt(NoOp.INSTANCE))); 57 | assertTrue(!p.equals(null)); 58 | } 59 | 60 | @Test 61 | public void testAdaptNull() throws Exception { 62 | assertNull(BinaryProcedureProcedure.adapt(null)); 63 | } 64 | 65 | @Test 66 | public void testAdapt() throws Exception { 67 | assertNotNull(BinaryProcedureProcedure.adapt(NoOp.INSTANCE)); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/adapter/TestNullaryPredicatePredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.adapter; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertNotNull; 21 | import static org.junit.Assert.assertNull; 22 | import static org.junit.Assert.assertTrue; 23 | 24 | import org.apache.commons.functor.BaseFunctorTest; 25 | import org.apache.commons.functor.Predicate; 26 | import org.apache.commons.functor.core.Constant; 27 | import org.junit.Test; 28 | 29 | /** 30 | */ 31 | public class TestNullaryPredicatePredicate extends BaseFunctorTest { 32 | 33 | // Functor Testing Framework 34 | // ------------------------------------------------------------------------ 35 | 36 | @Override 37 | protected Object makeFunctor() { 38 | return new NullaryPredicatePredicate(Constant.TRUE); 39 | } 40 | 41 | // Tests 42 | // ------------------------------------------------------------------------ 43 | 44 | @Test 45 | public void testEvaluate() throws Exception { 46 | Predicate p = new NullaryPredicatePredicate(Constant.TRUE); 47 | assertTrue(p.test(null)); 48 | } 49 | 50 | @Test 51 | public void testEquals() throws Exception { 52 | Predicate p = new NullaryPredicatePredicate(Constant.TRUE); 53 | assertEquals(p,p); 54 | assertObjectsAreEqual(p,new NullaryPredicatePredicate(Constant.TRUE)); 55 | assertObjectsAreNotEqual(p,Constant.TRUE); 56 | assertObjectsAreNotEqual(p,new NullaryPredicatePredicate(Constant.FALSE)); 57 | assertObjectsAreNotEqual(p,Constant.FALSE); 58 | assertTrue(!p.equals(null)); 59 | } 60 | 61 | @Test 62 | public void testAdaptNull() throws Exception { 63 | assertNull(NullaryPredicatePredicate.adapt(null)); 64 | } 65 | 66 | @Test 67 | public void testAdapt() throws Exception { 68 | assertNotNull(NullaryPredicatePredicate.adapt(Constant.TRUE)); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/aggregator/functions/DoubleSumAggregatorBinaryFunctionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.aggregator.functions; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertNull; 21 | 22 | import java.util.Random; 23 | 24 | import org.apache.commons.functor.BaseFunctorTest; 25 | import org.apache.commons.functor.aggregator.functions.DoubleSumAggregatorBinaryFunction; 26 | import org.junit.Test; 27 | 28 | /** 29 | * Unit test for {@link DoubleSumAggregatorBinaryFunction}. 30 | */ 31 | public class DoubleSumAggregatorBinaryFunctionTest extends BaseFunctorTest { 32 | private static final double DELTA = 0.01; //make room for some poor floating point support 33 | 34 | @Override 35 | protected Object makeFunctor() throws Exception { 36 | return new DoubleSumAggregatorBinaryFunction(); 37 | } 38 | 39 | @Test 40 | public void testNulls() throws Exception { 41 | DoubleSumAggregatorBinaryFunction fct = (DoubleSumAggregatorBinaryFunction)makeFunctor(); 42 | Double d = fct.evaluate(null, null); 43 | assertNull( d ); 44 | d = fct.evaluate( null, 1.0 ); 45 | assertEquals( 1.0, d.doubleValue(), DELTA ); 46 | d = fct.evaluate( 2.0, null ); 47 | assertEquals( 2.0, d.doubleValue(), DELTA ); 48 | } 49 | 50 | @Test 51 | public void testSum() throws Exception { 52 | DoubleSumAggregatorBinaryFunction fct = (DoubleSumAggregatorBinaryFunction)makeFunctor(); 53 | double total = 0.0; 54 | double result = 0.0; 55 | int calls = 31; 56 | Random rnd = new Random(); 57 | for( int i = 0; i < calls; i++ ) { 58 | double number = rnd.nextDouble(); 59 | total += number; 60 | result = fct.evaluate(result, number); 61 | assertEquals( result, total, DELTA ); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/aggregator/functions/IntCountAggregatorBinaryFunctionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.aggregator.functions; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertNotNull; 21 | import static org.junit.Assert.assertNull; 22 | 23 | import org.apache.commons.functor.BaseFunctorTest; 24 | import org.apache.commons.functor.aggregator.functions.IntegerCountAggregatorBinaryFunction; 25 | import org.junit.Test; 26 | 27 | /** 28 | * Unit test for {@link IntegerCountAggregatorBinaryFunction}. 29 | */ 30 | public class IntCountAggregatorBinaryFunctionTest extends BaseFunctorTest { 31 | @Override 32 | protected Object makeFunctor() throws Exception { 33 | return new IntegerCountAggregatorBinaryFunction(); 34 | } 35 | 36 | @Test 37 | public void testNull() throws Exception { 38 | IntegerCountAggregatorBinaryFunction fct = (IntegerCountAggregatorBinaryFunction)makeFunctor(); 39 | Integer i = fct.evaluate(null, null); 40 | assertNull( i ); 41 | i = fct.evaluate( null, 1 ); 42 | assertNull( i ); 43 | i = fct.evaluate( 2, null ); 44 | assertNotNull( i ); 45 | assertEquals( i.intValue(), 3 ); 46 | } 47 | 48 | @Test 49 | public void testCount() throws Exception { 50 | IntegerCountAggregatorBinaryFunction fct = (IntegerCountAggregatorBinaryFunction)makeFunctor(); 51 | int count = 0; 52 | int calls = 31; 53 | for( int i = 1; i <= calls; i++ ) { 54 | count = fct.evaluate(count, 12345); 55 | assertEquals( i, count ); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/aggregator/functions/IntMaxAggregatorBinaryFunctionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.aggregator.functions; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertNull; 21 | 22 | import java.util.Random; 23 | 24 | import org.apache.commons.functor.BaseFunctorTest; 25 | import org.apache.commons.functor.aggregator.functions.IntegerMaxAggregatorBinaryFunction; 26 | import org.junit.Test; 27 | 28 | /** 29 | * Unit test for {@link IntegerMaxAggregatorBinaryFunction}. 30 | */ 31 | public class IntMaxAggregatorBinaryFunctionTest extends BaseFunctorTest { 32 | @Override 33 | protected Object makeFunctor() throws Exception { 34 | return new IntegerMaxAggregatorBinaryFunction(); 35 | } 36 | 37 | @Test 38 | public void testNulls() throws Exception { 39 | IntegerMaxAggregatorBinaryFunction fct = (IntegerMaxAggregatorBinaryFunction) makeFunctor(); 40 | Integer d = fct.evaluate(null, null); 41 | assertNull(d); 42 | d = fct.evaluate(null, 1); 43 | assertEquals(1, d.intValue()); 44 | d = fct.evaluate(2, null); 45 | assertEquals(2, d.intValue()); 46 | } 47 | 48 | @Test 49 | public void testMax() throws Exception { 50 | IntegerMaxAggregatorBinaryFunction fct = (IntegerMaxAggregatorBinaryFunction) makeFunctor(); 51 | int max = 0; 52 | int result = 0; 53 | int number1 = 0; 54 | int number2 = 0; 55 | int calls = 31; 56 | Random rnd = new Random(); 57 | for (int i = 0; i < calls; i++) { 58 | number1 = rnd.nextInt(); 59 | number2 = rnd.nextInt(); 60 | max = Math.max(number1, number2); 61 | result = fct.evaluate(number1, number2); 62 | assertEquals(result, max); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/aggregator/functions/IntSumAggregatorBinaryFunctionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.aggregator.functions; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertNull; 21 | 22 | import java.util.Random; 23 | 24 | import org.apache.commons.functor.BaseFunctorTest; 25 | import org.apache.commons.functor.aggregator.functions.IntegerSumAggregatorBinaryFunction; 26 | import org.junit.Test; 27 | 28 | /** 29 | * Unit test for {@link IntegerSumAggregatorBinaryFunction}. 30 | */ 31 | public class IntSumAggregatorBinaryFunctionTest extends BaseFunctorTest { 32 | @Override 33 | protected Object makeFunctor() throws Exception { 34 | return new IntegerSumAggregatorBinaryFunction(); 35 | } 36 | 37 | @Test 38 | public void testNulls() throws Exception { 39 | IntegerSumAggregatorBinaryFunction fct = (IntegerSumAggregatorBinaryFunction) makeFunctor(); 40 | Integer d = fct.evaluate(null, null); 41 | assertNull(d); 42 | d = fct.evaluate(null, 1); 43 | assertEquals(1, d.intValue()); 44 | d = fct.evaluate(2, null); 45 | assertEquals(2, d.intValue()); 46 | } 47 | 48 | @Test 49 | public void testSum() throws Exception { 50 | IntegerSumAggregatorBinaryFunction fct = (IntegerSumAggregatorBinaryFunction) makeFunctor(); 51 | int total = 0; 52 | int result = 0; 53 | int calls = 31; 54 | Random rnd = new Random(); 55 | for (int i = 0; i < calls; i++) { 56 | int number = rnd.nextInt(); 57 | total += number; 58 | result = fct.evaluate(result, number); 59 | assertEquals(result, total); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/core/TestIsNotNull.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.core; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertTrue; 21 | 22 | import org.apache.commons.functor.BaseFunctorTest; 23 | import org.apache.commons.functor.Predicate; 24 | import org.junit.Test; 25 | 26 | /** 27 | */ 28 | public class TestIsNotNull extends BaseFunctorTest { 29 | 30 | // Functor Testing Framework 31 | // ------------------------------------------------------------------------ 32 | 33 | @Override 34 | protected Object makeFunctor() { 35 | return new IsNotNull(); 36 | } 37 | 38 | // Tests 39 | // ------------------------------------------------------------------------ 40 | 41 | @Test 42 | public void testTest() throws Exception { 43 | Predicate p = new IsNotNull(); 44 | assertTrue(!p.test(null)); 45 | assertTrue(p.test("foo")); 46 | assertTrue(p.test(Integer.valueOf(3))); 47 | } 48 | 49 | @Test 50 | public void testEquals() throws Exception { 51 | Predicate p = new IsNotNull(); 52 | assertEquals(p, p); 53 | assertObjectsAreEqual(p, new IsNotNull()); 54 | assertObjectsAreEqual(p, IsNotNull.instance()); 55 | assertObjectsAreNotEqual(p, Constant.TRUE); 56 | } 57 | 58 | @Test 59 | public void testConstant() throws Exception { 60 | assertEquals(IsNotNull.instance(), IsNotNull.instance()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/core/TestIsNull.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.core; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertFalse; 21 | import static org.junit.Assert.assertTrue; 22 | 23 | import org.apache.commons.functor.BaseFunctorTest; 24 | import org.apache.commons.functor.Predicate; 25 | import org.junit.Test; 26 | 27 | /** 28 | */ 29 | public class TestIsNull extends BaseFunctorTest { 30 | 31 | // Functor Testing Framework 32 | // ------------------------------------------------------------------------ 33 | 34 | @Override 35 | protected Object makeFunctor() { 36 | return new IsNull(); 37 | } 38 | 39 | // Tests 40 | // ------------------------------------------------------------------------ 41 | 42 | @Test 43 | public void testTest() throws Exception { 44 | Predicate p = new IsNull(); 45 | assertTrue(p.test(null)); 46 | assertFalse(p.test("foo")); 47 | assertFalse(p.test(Integer.valueOf(3))); 48 | } 49 | 50 | @Test 51 | public void testAsBinary() throws Exception { 52 | assertTrue(IsNull.left().test(null, "not null")); 53 | assertFalse(IsNull.left().test("not null", null)); 54 | assertTrue(IsNull.right().test("not null", null)); 55 | assertFalse(IsNull.right().test(null, "not null")); 56 | } 57 | 58 | @Test 59 | public void testEquals() throws Exception { 60 | Predicate p = new IsNull(); 61 | assertEquals(p, p); 62 | assertObjectsAreEqual(p, new IsNull()); 63 | assertObjectsAreEqual(p, IsNull.instance()); 64 | assertObjectsAreNotEqual(p, Constant.TRUE); 65 | } 66 | 67 | @Test 68 | public void testConstant() throws Exception { 69 | assertEquals(IsNull.instance(), IsNull.instance()); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/core/algorithm/TestDoUntil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.core.algorithm; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | import org.apache.commons.functor.BaseFunctorTest; 22 | import org.apache.commons.functor.NullaryProcedure; 23 | import org.apache.commons.functor.core.Offset; 24 | import org.junit.Test; 25 | 26 | /** 27 | * Tests {@link DoUntil} algorithm. 28 | */ 29 | public class TestDoUntil extends BaseFunctorTest { 30 | 31 | // Functor Testing Framework 32 | // ------------------------------------------------------------------------ 33 | 34 | @Override 35 | protected Object makeFunctor() throws Exception { 36 | Counter counter = new Counter(); 37 | return new DoUntil(counter, new Offset(10)); 38 | } 39 | 40 | @Test 41 | public void testDoUntil() { 42 | for(int i=0;i<3;++i){ 43 | Counter counter = new Counter(); 44 | new DoUntil(counter, new Offset(i)).run(); 45 | assertEquals(i+1,counter.count); 46 | } 47 | } 48 | 49 | // Classes 50 | // ------------------------------------------------------------------------ 51 | 52 | static class Counter implements NullaryProcedure { 53 | public void run() { 54 | count++; 55 | } 56 | public int count = 0; 57 | 58 | @Override 59 | public boolean equals(Object obj) { 60 | if(this == obj) { 61 | return true; 62 | } 63 | if (obj == null || !obj.getClass().equals(getClass())) { 64 | return false; 65 | } 66 | Counter that = (Counter)obj; 67 | return this.count == that.count; 68 | } 69 | 70 | @Override 71 | public int hashCode() { 72 | int hash = "Counter".hashCode(); 73 | hash <<= 2; 74 | hash ^= this.count; 75 | return hash; 76 | } 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/core/algorithm/TestDoWhile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.core.algorithm; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | import org.apache.commons.functor.BaseFunctorTest; 22 | import org.apache.commons.functor.NullaryProcedure; 23 | import org.apache.commons.functor.core.Limit; 24 | import org.junit.Test; 25 | 26 | /** 27 | * Tests {@link DoWhile} algorithm. 28 | */ 29 | public class TestDoWhile extends BaseFunctorTest { 30 | 31 | // Functor Testing Framework 32 | // ------------------------------------------------------------------------ 33 | 34 | @Override 35 | protected Object makeFunctor() throws Exception { 36 | Counter counter = new Counter(); 37 | return new DoWhile(counter, new Limit(10)); 38 | } 39 | 40 | @Test 41 | public void testDoWhile() { 42 | for(int i=0;i<3;i++){ 43 | Counter counter = new Counter(); 44 | new DoWhile(counter, new Limit(i)).run(); 45 | assertEquals(i+1,counter.count); 46 | } 47 | } 48 | 49 | // Classes 50 | // ------------------------------------------------------------------------ 51 | 52 | static class Counter implements NullaryProcedure { 53 | public void run() { 54 | count++; 55 | } 56 | public int count = 0; 57 | 58 | @Override 59 | public boolean equals(Object obj) { 60 | if(this == obj) { 61 | return true; 62 | } 63 | if (obj == null || !obj.getClass().equals(getClass())) { 64 | return false; 65 | } 66 | Counter that = (Counter)obj; 67 | return this.count == that.count; 68 | } 69 | 70 | @Override 71 | public int hashCode() { 72 | int hash = "Counter".hashCode(); 73 | hash <<= 2; 74 | hash ^= this.count; 75 | return hash; 76 | } 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/core/algorithm/TestGeneratorContains.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.core.algorithm; 18 | 19 | import static org.junit.Assert.assertFalse; 20 | import static org.junit.Assert.assertTrue; 21 | 22 | import java.util.Arrays; 23 | import java.util.List; 24 | 25 | import org.apache.commons.functor.BaseFunctorTest; 26 | import org.apache.commons.functor.Predicate; 27 | import org.apache.commons.functor.adapter.LeftBoundPredicate; 28 | import org.apache.commons.functor.core.IsEqual; 29 | import org.apache.commons.functor.core.algorithm.GeneratorContains; 30 | import org.apache.commons.functor.generator.loop.IteratorToGeneratorAdapter; 31 | import org.junit.Test; 32 | 33 | /** 34 | * Tests {@link GeneratorContains} algorithm. 35 | */ 36 | public class TestGeneratorContains extends BaseFunctorTest { 37 | 38 | @Override 39 | protected Object makeFunctor() throws Exception { 40 | return new GeneratorContains(); 41 | } 42 | 43 | @Test 44 | public void testContains() { 45 | assertTrue(new GeneratorContains() 46 | .test(IteratorToGeneratorAdapter.adapt(list.iterator()), equalsThree)); 47 | assertFalse(new GeneratorContains().test(IteratorToGeneratorAdapter.adapt(list.iterator()), 48 | equalsTwentyThree)); 49 | } 50 | 51 | // Attributes 52 | // ------------------------------------------------------------------------ 53 | 54 | private List list = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); 55 | private Predicate equalsThree = LeftBoundPredicate.bind(IsEqual.instance(), Integer.valueOf(3)); 56 | private Predicate equalsTwentyThree = LeftBoundPredicate.bind(IsEqual.instance(), Integer.valueOf(23)); 57 | 58 | } 59 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/core/algorithm/TestIndexOfInGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.core.algorithm; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | import java.util.Arrays; 22 | import java.util.List; 23 | 24 | import org.apache.commons.functor.BaseFunctorTest; 25 | import org.apache.commons.functor.Predicate; 26 | import org.apache.commons.functor.adapter.LeftBoundPredicate; 27 | import org.apache.commons.functor.core.IsEqual; 28 | import org.apache.commons.functor.generator.loop.IteratorToGeneratorAdapter; 29 | import org.junit.Test; 30 | 31 | /** 32 | * Tests {@link IndexOfInGenerator} algorithm. 33 | */ 34 | public class TestIndexOfInGenerator extends BaseFunctorTest { 35 | 36 | @Override 37 | protected Object makeFunctor() throws Exception { 38 | return IndexOfInGenerator.instance(); 39 | } 40 | 41 | @Test 42 | public void testIndexOfInGenerator() { 43 | assertEquals(3L, new IndexOfInGenerator().evaluate(IteratorToGeneratorAdapter.adapt(list.iterator()),equalsThree)); 44 | } 45 | 46 | // Attributes 47 | // ------------------------------------------------------------------------ 48 | 49 | private List list = Arrays.asList(0,1,2,3,4,5,6,7,8,9); 50 | private Predicate equalsThree = LeftBoundPredicate.bind(IsEqual.instance(),Integer.valueOf(3)); 51 | 52 | } 53 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/core/algorithm/TestUntilDo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.core.algorithm; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | import org.apache.commons.functor.BaseFunctorTest; 22 | import org.apache.commons.functor.NullaryProcedure; 23 | import org.apache.commons.functor.core.Offset; 24 | import org.junit.Test; 25 | 26 | /** 27 | * Tests {@link UntilDo} algorithm. 28 | */ 29 | public class TestUntilDo extends BaseFunctorTest { 30 | 31 | // Functor Testing Framework 32 | // ------------------------------------------------------------------------ 33 | 34 | @Override 35 | protected Object makeFunctor() throws Exception { 36 | Counter counter = new Counter(); 37 | return new UntilDo(new Offset(10), counter); 38 | } 39 | 40 | @Test 41 | public void testUntilDo() { 42 | for (int i=0;i<3;i++){ 43 | Counter counter = new Counter(); 44 | new UntilDo(new Offset(i), counter).run(); 45 | assertEquals(i,counter.count); 46 | } 47 | } 48 | 49 | // Classes 50 | // ------------------------------------------------------------------------ 51 | 52 | static class Counter implements NullaryProcedure { 53 | public void run() { 54 | count++; 55 | } 56 | public int count = 0; 57 | 58 | @Override 59 | public boolean equals(Object obj) { 60 | if(this == obj) { 61 | return true; 62 | } 63 | if (obj == null || !obj.getClass().equals(getClass())) { 64 | return false; 65 | } 66 | Counter that = (Counter)obj; 67 | return this.count == that.count; 68 | } 69 | 70 | @Override 71 | public int hashCode() { 72 | int hash = "Counter".hashCode(); 73 | hash <<= 2; 74 | hash ^= this.count; 75 | return hash; 76 | } 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/core/comparator/TestComparableComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.core.comparator; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertTrue; 21 | 22 | import org.junit.Test; 23 | 24 | /** 25 | */ 26 | public class TestComparableComparator { 27 | 28 | // Tests 29 | // ------------------------------------------------------------------------ 30 | 31 | @Test 32 | public void testCompareIntegers() { 33 | assertTrue(ComparableComparator. instance().compare(Integer.valueOf(Integer.MIN_VALUE), 34 | Integer.valueOf(Integer.MIN_VALUE)) == 0); 35 | assertTrue(ComparableComparator. instance().compare(Integer.valueOf(-1), Integer.valueOf(-1)) == 0); 36 | assertTrue(ComparableComparator. instance().compare(Integer.valueOf(0), Integer.valueOf(0)) == 0); 37 | assertTrue(ComparableComparator. instance().compare(Integer.valueOf(Integer.MAX_VALUE), 38 | Integer.valueOf(Integer.MAX_VALUE)) == 0); 39 | assertTrue(ComparableComparator. instance().compare(Integer.valueOf(1), Integer.valueOf(1)) == 0); 40 | } 41 | 42 | @Test(expected = NullPointerException.class) 43 | public void testCompareNull() { 44 | ComparableComparator. instance().compare(null, Integer.valueOf(2)); 45 | } 46 | 47 | @Test 48 | public void testEqualsAndHashCode() { 49 | assertEquals(new ComparableComparator(), new ComparableComparator()); 50 | assertEquals(new ComparableComparator().hashCode(), new ComparableComparator().hashCode()); 51 | assertTrue(!new ComparableComparator().equals(null)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/core/comparator/TestIsEquivalent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.core.comparator; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertFalse; 21 | import static org.junit.Assert.assertTrue; 22 | 23 | import org.apache.commons.functor.core.Constant; 24 | import org.junit.Test; 25 | 26 | /** 27 | */ 28 | public class TestIsEquivalent extends BaseComparisonPredicateTest { 29 | 30 | // Functor Testing Framework 31 | // ------------------------------------------------------------------------ 32 | 33 | @Override 34 | protected Object makeFunctor() { 35 | return IsEquivalent.INSTANCE; 36 | } 37 | 38 | // Tests 39 | // ------------------------------------------------------------------------ 40 | 41 | @Test 42 | public void testTest() throws Exception { 43 | IsEquivalent p = IsEquivalent. instance(); 44 | assertTrue(!p.test(Integer.valueOf(2), Integer.valueOf(4))); 45 | assertTrue(!p.test(Integer.valueOf(3), Integer.valueOf(4))); 46 | assertTrue(p.test(Integer.valueOf(4), Integer.valueOf(4))); 47 | assertTrue(!p.test(Integer.valueOf(5), Integer.valueOf(4))); 48 | assertTrue(!p.test(Integer.valueOf(6), Integer.valueOf(4))); 49 | } 50 | 51 | @Test 52 | public void testInstance() { 53 | assertTrue(IsEquivalent.instance("Xyzzy").test("Xyzzy")); 54 | assertTrue(!IsEquivalent.instance("Xyzzy").test("z")); 55 | } 56 | 57 | @Test 58 | public void testEquals() throws Exception { 59 | IsEquivalent> p = IsEquivalent.instance(); 60 | assertEquals(p, p); 61 | 62 | assertObjectsAreEqual(p, new IsEquivalent>()); 63 | assertObjectsAreEqual(p, new IsEquivalent(ComparableComparator. instance())); 64 | assertObjectsAreNotEqual(p, Constant.FALSE); 65 | assertFalse(p.equals(null)); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/core/composite/TestAbstractLoopNullaryProcedure.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.core.composite; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | import org.apache.commons.functor.BaseFunctorTest; 22 | import org.apache.commons.functor.NullaryPredicate; 23 | import org.apache.commons.functor.NullaryProcedure; 24 | import org.apache.commons.functor.core.Constant; 25 | import org.apache.commons.functor.core.NoOp; 26 | import org.junit.Test; 27 | 28 | /** 29 | */ 30 | public class TestAbstractLoopNullaryProcedure extends BaseFunctorTest { 31 | 32 | // Functor Testing Framework 33 | // ------------------------------------------------------------------------ 34 | 35 | @Override 36 | protected Object makeFunctor() { 37 | return new MockLoopProcedure(Constant.FALSE, NoOp.INSTANCE); 38 | } 39 | 40 | // Tests 41 | // ------------------------------------------------------------------------ 42 | 43 | @Test 44 | public void testEquals() { 45 | MockLoopProcedure p = new MockLoopProcedure(Constant.FALSE, NoOp.INSTANCE); 46 | assertEquals(p,p); 47 | assertObjectsAreEqual(p,new MockLoopProcedure(Constant.FALSE, NoOp.INSTANCE)); 48 | assertObjectsAreNotEqual(p,new MockLoopProcedure(Constant.TRUE, NoOp.INSTANCE)); 49 | assertObjectsAreNotEqual(p,new MockLoopProcedure(Constant.FALSE, new NullarySequence())); 50 | } 51 | } 52 | 53 | class MockLoopProcedure extends AbstractLoopNullaryProcedure { 54 | public MockLoopProcedure(NullaryPredicate condition, NullaryProcedure action) { 55 | super(condition,action); 56 | } 57 | 58 | public void run() { 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/core/composite/TestComposite.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.core.composite; 18 | 19 | import static org.junit.Assert.assertNotNull; 20 | 21 | import org.apache.commons.functor.core.Identity; 22 | import org.apache.commons.functor.core.LeftIdentity; 23 | import org.apache.commons.functor.core.NoOp; 24 | import org.apache.commons.functor.core.comparator.IsGreaterThan; 25 | import org.junit.Test; 26 | 27 | /** 28 | */ 29 | public class TestComposite { 30 | 31 | // Tests 32 | // ------------------------------------------------------------------------ 33 | 34 | @Test 35 | public void testUnaryMethods() { 36 | assertNotNull(Composite.procedure(NoOp.instance())); 37 | assertNotNull(Composite.procedure(NoOp.instance(),Identity.instance())); 38 | assertNotNull(Composite.predicate(Identity.instance())); 39 | assertNotNull(Composite.predicate(Identity.instance(),Identity.instance())); 40 | assertNotNull(Composite.function(Identity.instance())); 41 | assertNotNull(Composite.function(Identity.instance(),Identity.instance())); 42 | } 43 | 44 | @Test 45 | public void testBinaryMethods() { 46 | assertNotNull(Composite.function(LeftIdentity.function(),LeftIdentity.function(),LeftIdentity.function())); 47 | assertNotNull(Composite.predicate(IsGreaterThan.instance(),new Identity>(),new Identity>())); 48 | assertNotNull(Composite.function(LeftIdentity.function(),Identity.instance(),Identity.instance())); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/core/composite/TestNot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.core.composite; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertNotNull; 21 | import static org.junit.Assert.assertNull; 22 | import static org.junit.Assert.assertTrue; 23 | 24 | import org.apache.commons.functor.BaseFunctorTest; 25 | import org.apache.commons.functor.Predicate; 26 | import org.apache.commons.functor.core.Constant; 27 | import org.junit.Test; 28 | 29 | /** 30 | */ 31 | public class TestNot extends BaseFunctorTest { 32 | 33 | // Functor Testing Framework 34 | // ------------------------------------------------------------------------ 35 | 36 | @Override 37 | protected Object makeFunctor() { 38 | return new Not(Constant.TRUE); 39 | } 40 | 41 | // Tests 42 | // ------------------------------------------------------------------------ 43 | 44 | @Test 45 | public void testTest() throws Exception { 46 | Predicate truePred = new Not(Constant.FALSE); 47 | assertTrue(truePred.test(null)); 48 | assertTrue(truePred.test("xyzzy")); 49 | assertTrue(truePred.test(Integer.valueOf(3))); 50 | } 51 | 52 | @Test 53 | public void testEquals() throws Exception { 54 | Not p = new Not(Constant.TRUE); 55 | assertEquals(p, p); 56 | assertObjectsAreEqual(p, new Not(Constant.TRUE)); 57 | assertObjectsAreEqual(p, Not.not(Constant.TRUE)); 58 | assertObjectsAreNotEqual(p, new Not(Constant.FALSE)); 59 | assertObjectsAreNotEqual(p, Constant.TRUE); 60 | assertTrue(!p.equals(null)); 61 | } 62 | 63 | @Test 64 | public void testNotNull() throws Exception { 65 | assertNull(Not.not(null)); 66 | } 67 | 68 | @Test 69 | public void testNotNotNull() throws Exception { 70 | assertNotNull(Not.not(Constant.truePredicate())); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/aggregator/list/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | /** 18 | * Package which groups a set of examples for list-backed {@link org.apache.commons.functor.aggregator.Aggregator}. 19 | */ 20 | package org.apache.commons.functor.example.aggregator.list; 21 | 22 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/aggregator/nostore/AggregatedFunctionSample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.functor.example.aggregator.nostore; 19 | 20 | import org.apache.commons.functor.BinaryFunction; 21 | import org.apache.commons.functor.aggregator.AbstractNoStoreAggregator; 22 | 23 | /** 24 | * Shows how to implement own aggregated function to use with 25 | * {@link AbstractNoStoreAggregator}. 26 | */ 27 | public class AggregatedFunctionSample { 28 | /** 29 | * Uses a custom function together with a nostore aggregator to provide a 30 | * continuous logical OR in between all the values added to the aggregator. 31 | */ 32 | public void useOwnFunction() throws Exception { 33 | AbstractNoStoreAggregator or = new AbstractNoStoreAggregator( new OwnBinaryFunction() ) { 34 | @Override 35 | protected Boolean initialValue() { 36 | return false; 37 | } 38 | }; 39 | or.add( false ); 40 | System.out.println( "OR : " + or.evaluate() ); 41 | or.add( true ); 42 | System.out.println( "OR : " + or.evaluate() ); 43 | or.add( false ); 44 | System.out.println( "OR : " + or.evaluate() ); 45 | } 46 | 47 | /** 48 | * This class implements a logical OR: it OR's the 2 parameters passed in 49 | * and returns the result. 50 | * (There are similar implementations already in functor, this is just to 51 | * be used as an example for doing this with a nostore aggregator. 52 | */ 53 | static class OwnBinaryFunction implements BinaryFunction { 54 | public Boolean evaluate(Boolean left, Boolean right) { 55 | return left.booleanValue() || right.booleanValue(); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/aggregator/nostore/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Package which groups a set of examples for {@link org.apache.commons.functor.aggregator.AbstractNoStoreAggregator}. 20 | */ 21 | package org.apache.commons.functor.example.aggregator.nostore; 22 | 23 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/aggregator/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | /** 18 | * Package which groups a set of examples for {@link org.apache.commons.functor.aggregator.Aggregator}. 19 | */ 20 | package org.apache.commons.functor.example.aggregator; 21 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/kata/four/Abs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.kata.four; 18 | 19 | import org.apache.commons.functor.Function; 20 | 21 | /** 22 | * Evaluates to the absolute Integer value of the Number-valued 23 | * input parameter. 24 | */ 25 | public final class Abs implements Function { 26 | 27 | public Integer evaluate(Number num) { 28 | return Integer.valueOf(Math.abs(num.intValue())); 29 | } 30 | 31 | public static final Abs instance() { 32 | return INSTANCE; 33 | } 34 | 35 | private static final Abs INSTANCE = new Abs(); 36 | } -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/kata/four/IsInteger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.kata.four; 18 | 19 | import org.apache.commons.functor.Predicate; 20 | 21 | /** 22 | * Tests to true iff the input object can be converted to 23 | * an Integer by {@link ToInteger}. 24 | */ 25 | public final class IsInteger implements Predicate { 26 | public boolean test(String obj) { 27 | try { 28 | ToInteger.instance().evaluate(obj); 29 | return true; 30 | } catch (RuntimeException e){ 31 | return false; 32 | } 33 | } 34 | 35 | public static final IsInteger instance() { 36 | return INSTANCE; 37 | } 38 | 39 | private static final IsInteger INSTANCE = new IsInteger(); 40 | } -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/kata/four/NthColumn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.kata.four; 18 | 19 | import java.util.StringTokenizer; 20 | 21 | import org.apache.commons.functor.Function; 22 | 23 | /** 24 | * Evaluates the input String to extrace the nth whitespace 25 | * delmited column. 26 | */ 27 | public final class NthColumn implements Function { 28 | public NthColumn(int n) { 29 | this.n = n; 30 | } 31 | 32 | public String evaluate(String obj) { 33 | StringTokenizer toker = new StringTokenizer(obj); 34 | for (int count = 0; count < n && toker.hasMoreTokens();count++) { 35 | toker.nextToken(); 36 | } 37 | return toker.hasMoreTokens() ? toker.nextToken() : null; 38 | } 39 | 40 | private final int n; 41 | 42 | public static final NthColumn instance(int n) { 43 | return new NthColumn(n); 44 | } 45 | } -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/kata/four/TestSoccer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.kata.four; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | import org.junit.Test; 22 | 23 | /** 24 | * See http://pragprog.com/pragdave/Practices/Kata/KataFour.rdoc,v 25 | * for more information on this Kata. 26 | */ 27 | public class TestSoccer { 28 | 29 | @Test 30 | public void testProcess() { 31 | // for our soccer example, we want to select the second column of the 32 | // line with the minimal difference between the seventh and ninth columns. 33 | assertEquals( 34 | "Aston_Villa", 35 | DataMunger.process(getClass().getResourceAsStream("soccer.txt"),1,6,8)); 36 | } 37 | 38 | } 39 | 40 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/kata/four/TestWeather.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.kata.four; 18 | 19 | import junit.framework.Test; 20 | import junit.framework.TestCase; 21 | import junit.framework.TestSuite; 22 | 23 | /** 24 | * See http://pragprog.com/pragdave/Practices/Kata/KataFour.rdoc,v 25 | * for more information on this Kata. 26 | */ 27 | public class TestWeather extends TestCase { 28 | public TestWeather(String testName) { 29 | super(testName); 30 | } 31 | 32 | public static Test suite() { 33 | return new TestSuite(TestWeather.class); 34 | } 35 | 36 | public void testProcess() { 37 | // for our soccer example, we want to select the first column of the 38 | // line with the minimal difference between the second and third columns. 39 | assertEquals( 40 | "14", 41 | DataMunger.process(getClass().getResourceAsStream("weather.txt"),0,1,2)); 42 | } 43 | 44 | } 45 | 46 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/kata/four/ToInteger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.kata.four; 18 | 19 | import org.apache.commons.functor.Function; 20 | 21 | /** 22 | * Converts a String value to an Integer, throwing an exception if no such conversion can be made. 23 | * 24 | * Trailing, non-{@link Character#isDigit digit} characters are ignored. 25 | * 26 | */ 27 | public final class ToInteger implements Function { 28 | 29 | public Integer evaluate(String str) { 30 | StringBuilder buf = new StringBuilder(); 31 | for (int i = 0; i < str.length(); i++) { 32 | if (Character.isDigit(str.charAt(i))) { 33 | buf.append(str.charAt(i)); 34 | } else { 35 | break; 36 | } 37 | } 38 | try { 39 | return Integer.valueOf(buf.toString()); 40 | } catch (NumberFormatException e) { 41 | throw new NumberFormatException(str); 42 | } 43 | } 44 | 45 | public static final ToInteger instance() { 46 | return INSTANCE; 47 | } 48 | 49 | private static final ToInteger INSTANCE = new ToInteger(); 50 | } 51 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/kata/one/Add.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.kata.one; 18 | 19 | import org.apache.commons.functor.Function; 20 | import org.apache.commons.functor.adapter.LeftBoundFunction; 21 | 22 | /** 23 | */ 24 | public class Add extends ArithmeticOperation { 25 | public Number evaluate(Number left, Number right) { 26 | return Integer.valueOf(left.intValue() + right.intValue()); 27 | } 28 | 29 | public static Add instance() { 30 | return INSTANCE; 31 | } 32 | 33 | public static Function to(int factor) { 34 | return LeftBoundFunction.bind(INSTANCE, factor); 35 | } 36 | 37 | private static Add INSTANCE = new Add(); 38 | } 39 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/kata/one/ArithmeticOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.kata.one; 18 | 19 | import org.apache.commons.functor.BinaryFunction; 20 | 21 | public abstract class ArithmeticOperation implements BinaryFunction { 22 | } 23 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/kata/one/Divide.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.kata.one; 18 | 19 | import org.apache.commons.functor.Function; 20 | import org.apache.commons.functor.adapter.RightBoundFunction; 21 | 22 | /** 23 | */ 24 | public class Divide extends ArithmeticOperation { 25 | 26 | public Number evaluate(Number left, Number right) { 27 | return Integer.valueOf(left.intValue() / right.intValue()); 28 | } 29 | 30 | public static Divide instance() { 31 | return INSTANCE; 32 | } 33 | 34 | public static Function by(int factor) { 35 | return RightBoundFunction.bind(INSTANCE, factor); 36 | } 37 | 38 | private static Divide INSTANCE = new Divide(); 39 | } 40 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/kata/one/Mod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.kata.one; 18 | 19 | import org.apache.commons.functor.Function; 20 | import org.apache.commons.functor.adapter.RightBoundFunction; 21 | 22 | /** 23 | */ 24 | public class Mod extends ArithmeticOperation { 25 | public Number evaluate(Number left, Number right) { 26 | return Integer.valueOf(left.intValue() % right.intValue()); 27 | } 28 | 29 | public static Mod instance() { 30 | return INSTANCE; 31 | } 32 | 33 | public static Function by(int factor) { 34 | return RightBoundFunction.bind(instance(),factor); 35 | } 36 | 37 | private static Mod INSTANCE = new Mod(); 38 | } 39 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/kata/one/Money.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.kata.one; 18 | 19 | /** 20 | */ 21 | public class Money { 22 | public Money(int cents) { 23 | this.cents = cents; 24 | } 25 | 26 | public int getValueAsCents() { 27 | return cents; 28 | } 29 | 30 | @Override 31 | public boolean equals(Object obj) { 32 | if (obj instanceof Money) { 33 | Money that = (Money) obj; 34 | return getValueAsCents() == that.getValueAsCents(); 35 | } else { 36 | return false; 37 | } 38 | } 39 | 40 | @Override 41 | public int hashCode() { 42 | return getValueAsCents(); 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return getValueAsCents() + " cents"; 48 | } 49 | 50 | private int cents; 51 | } 52 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/kata/one/Multiply.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.kata.one; 18 | 19 | import org.apache.commons.functor.Function; 20 | import org.apache.commons.functor.adapter.LeftBoundFunction; 21 | 22 | /** 23 | */ 24 | public class Multiply extends ArithmeticOperation { 25 | 26 | public Number evaluate(Number left, Number right) { 27 | return Integer.valueOf(left.intValue() * right.intValue()); 28 | } 29 | 30 | public static Multiply instance() { 31 | return INSTANCE; 32 | } 33 | 34 | public static Function by(int factor) { 35 | return LeftBoundFunction.bind(INSTANCE, factor); 36 | } 37 | 38 | private static Multiply INSTANCE = new Multiply(); 39 | } 40 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/kata/one/Product.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.kata.one; 18 | 19 | import org.apache.commons.functor.Function; 20 | 21 | 22 | /** 23 | */ 24 | public class Product { 25 | public Product(String name, String sku, int cost) { 26 | this(name,sku,ToMoney.from(Multiply.by(cost))); 27 | } 28 | 29 | public Product(String name, String sku, Function price) { 30 | this.name = name; 31 | this.sku = sku; 32 | this.priceFunction = price; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public Function getPriceFunction() { 40 | return priceFunction; 41 | } 42 | 43 | public String getSku() { 44 | return sku; 45 | } 46 | 47 | public void setName(String string) { 48 | name = string; 49 | } 50 | 51 | public void setPriceFunction(Function function) { 52 | priceFunction = function; 53 | } 54 | 55 | public void setSku(String string) { 56 | sku = string; 57 | } 58 | 59 | public Money getPrice(int quantity) { 60 | return priceFunction.evaluate(quantity); 61 | } 62 | 63 | private String name; 64 | private String sku; 65 | private Function priceFunction; 66 | } 67 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/kata/one/Subtract.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.kata.one; 18 | 19 | import org.apache.commons.functor.Function; 20 | import org.apache.commons.functor.adapter.LeftBoundFunction; 21 | 22 | /** 23 | */ 24 | public class Subtract extends ArithmeticOperation { 25 | public Number evaluate(Number left, Number right) { 26 | return Integer.valueOf(left.intValue() - right.intValue()); 27 | } 28 | 29 | public static Subtract instance() { 30 | return INSTANCE; 31 | } 32 | 33 | public static Function from(int factor) { 34 | return LeftBoundFunction.bind(INSTANCE, factor); 35 | } 36 | 37 | private static Subtract INSTANCE = new Subtract(); 38 | } 39 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/kata/one/ToMoney.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.kata.one; 18 | 19 | import org.apache.commons.functor.Function; 20 | import org.apache.commons.functor.core.composite.Composite; 21 | 22 | /** 23 | */ 24 | public class ToMoney implements Function { 25 | 26 | public Money evaluate(Number cents) { 27 | return new Money(cents.intValue()); 28 | } 29 | 30 | public static ToMoney instance() { 31 | return INSTANCE; 32 | } 33 | 34 | public static Function from(Function fn) { 35 | return Composite.function(INSTANCE, fn); 36 | } 37 | 38 | private static ToMoney INSTANCE = new ToMoney(); 39 | } 40 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/kata/two/BaseBinaryChop.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.kata.two; 18 | 19 | import java.util.Arrays; 20 | import java.util.List; 21 | 22 | /** 23 | * See http://pragprog.com/pragdave/Practices/Kata/KataTwo.rdoc,v for more information on this Kata. 24 | * 25 | */ 26 | public abstract class BaseBinaryChop implements BinaryChop { 27 | public int find(int seeking, int[] in) { 28 | Integer[] In = new Integer[in.length]; 29 | for (int i = 0; i < in.length; i++) { 30 | In[i] = Integer.valueOf(in[i]); 31 | } 32 | return find(Integer.valueOf(seeking), In); 33 | } 34 | 35 | public int find(Integer seeking, Integer[] in) { 36 | return find(seeking, Arrays.asList(in)); 37 | } 38 | 39 | protected static int compare(List list, int index, Integer obj) { 40 | return ((Comparable) list.get(index)).compareTo(obj); 41 | } 42 | 43 | protected static boolean greaterThan(List list, int index, Integer obj) { 44 | return compare(list, index, obj) > 0; 45 | } 46 | 47 | protected static boolean equals(List list, int index, Integer obj) { 48 | return compare(list, index, obj) == 0; 49 | } 50 | 51 | protected static final Integer NEGATIVE_ONE = Integer.valueOf(-1); 52 | 53 | } 54 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/kata/two/BinaryChop.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.kata.two; 18 | 19 | import java.util.List; 20 | 21 | /** 22 | * See http://pragprog.com/pragdave/Practices/Kata/KataTwo.rdoc,v 23 | * for more information on this Kata. 24 | */ 25 | public interface BinaryChop { 26 | int find(int seeking, int[] in); 27 | int find(Integer seeking, Integer[] in); 28 | int find(Integer seeking, List in); 29 | } -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/lines/Contains.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.lines; 18 | 19 | import org.apache.commons.functor.Predicate; 20 | 21 | 22 | /** 23 | */ 24 | public class Contains implements Predicate { 25 | public Contains(String str) { 26 | this.str = str; 27 | } 28 | 29 | public boolean test(T obj) { 30 | return null != obj && obj.toString().indexOf(str) != -1; 31 | } 32 | 33 | private String str = null; 34 | } 35 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/lines/Count.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.lines; 18 | 19 | import org.apache.commons.functor.NullaryProcedure; 20 | 21 | /** 22 | */ 23 | public class Count implements NullaryProcedure { 24 | public void run() { 25 | count++; 26 | } 27 | 28 | public int getCount() { 29 | return count; 30 | } 31 | 32 | private int count = 0; 33 | } 34 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/lines/StartsWith.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.lines; 18 | 19 | import org.apache.commons.functor.Predicate; 20 | 21 | 22 | /** 23 | */ 24 | public class StartsWith implements Predicate { 25 | public StartsWith(String prefix) { 26 | this.prefix = prefix; 27 | } 28 | 29 | public boolean test(T obj) { 30 | return null != obj && obj.toString().startsWith(prefix); 31 | } 32 | 33 | private String prefix = null; 34 | } 35 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/lines/Sum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.lines; 18 | 19 | import org.apache.commons.functor.BinaryFunction; 20 | 21 | /** 22 | */ 23 | public class Sum implements BinaryFunction { 24 | public Integer evaluate(Number left, Number right) { 25 | return left.intValue() + right.intValue(); 26 | } 27 | 28 | public static final Sum instance() { 29 | return INSTANCE; 30 | } 31 | 32 | private static final Sum INSTANCE = new Sum(); 33 | } 34 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/lines/TestAll.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.lines; 18 | 19 | import junit.framework.Test; 20 | import junit.framework.TestCase; 21 | import junit.framework.TestSuite; 22 | 23 | /** 24 | */ 25 | public class TestAll extends TestCase { 26 | public TestAll(String testName) { 27 | super(testName); 28 | } 29 | 30 | public static Test suite() { 31 | TestSuite suite = new TestSuite(); 32 | 33 | suite.addTest(TestLines.suite()); 34 | 35 | return suite; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/lines/WordCount.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.lines; 18 | 19 | import java.util.StringTokenizer; 20 | 21 | import org.apache.commons.functor.Function; 22 | 23 | /** 24 | */ 25 | public class WordCount implements Function { 26 | public Integer evaluate(String obj) { 27 | return new StringTokenizer(obj).countTokens(); 28 | } 29 | 30 | public static WordCount instance() { 31 | return INSTANCE; 32 | } 33 | 34 | private static final WordCount INSTANCE = new WordCount(); 35 | } 36 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/map/LazyMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.map; 18 | 19 | import java.util.Map; 20 | 21 | import org.apache.commons.functor.BinaryFunction; 22 | import org.apache.commons.functor.Function; 23 | 24 | /** 25 | */ 26 | public class LazyMap extends FunctoredMap { 27 | public LazyMap(Map map, final Function factory) { 28 | super(map); 29 | setOnGet(new BinaryFunction, K, V>() { 30 | public V evaluate(Map map, K key) { 31 | if (map.containsKey(key)) { 32 | return map.get(key); 33 | } else { 34 | V value = factory.evaluate(key); 35 | map.put(key,value); 36 | return value; 37 | } 38 | } 39 | }); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/map/PredicatedMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.map; 18 | 19 | import java.lang.reflect.Array; 20 | import java.util.Iterator; 21 | import java.util.Map; 22 | 23 | import org.apache.commons.functor.BinaryPredicate; 24 | import org.apache.commons.functor.BinaryProcedure; 25 | import org.apache.commons.functor.Predicate; 26 | import org.apache.commons.functor.adapter.BinaryProcedureBinaryFunction; 27 | import org.apache.commons.functor.core.composite.ConditionalBinaryFunction; 28 | 29 | /** 30 | */ 31 | public class PredicatedMap extends FunctoredMap { 32 | public PredicatedMap(Map map, final Predicate keyPredicate, final Predicate valuePredicate) { 33 | super(map); 34 | setOnPut(new ConditionalBinaryFunction, Object[], V>( 35 | new BinaryPredicate, Object[]>() { 36 | @SuppressWarnings("unchecked") 37 | public boolean test(Map a, Object[] b) { 38 | return keyPredicate.test((K)Array.get(b,0)) && 39 | valuePredicate.test((V)Array.get(b,1)); 40 | } 41 | }, 42 | DEFAULT_ON_PUT, 43 | BinaryProcedureBinaryFunction., Object[], V>adapt(new Throw, Object>(new IllegalArgumentException())))); 44 | 45 | setOnPutAll(new BinaryProcedure, Map>() { 46 | public void run(Map dest, Map src) { 47 | for (Iterator> iter = src.entrySet().iterator(); iter.hasNext(); ) { 48 | Map.Entry pair = iter.next(); 49 | if (keyPredicate.test(pair.getKey()) && 50 | valuePredicate.test(pair.getValue())) { 51 | dest.put(pair.getKey(),pair.getValue()); 52 | } 53 | } 54 | } 55 | }); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /core/src/test/java/org/apache/commons/functor/example/map/TestAll.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.functor.example.map; 18 | 19 | import junit.framework.Test; 20 | import junit.framework.TestCase; 21 | import junit.framework.TestSuite; 22 | 23 | /** 24 | */ 25 | public class TestAll extends TestCase { 26 | public TestAll(String testName) { 27 | super(testName); 28 | } 29 | 30 | public static Test suite() { 31 | TestSuite suite = new TestSuite(); 32 | 33 | suite.addTest(TestPredicatedMap.suite()); 34 | suite.addTest(TestFixedSizeMap.suite()); 35 | suite.addTest(TestLazyMap.suite()); 36 | 37 | return suite; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /core/src/test/resources/org/apache/commons/functor/example/kata/four/soccer.txt: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | English Premier League, 2001/2002 Tables 17 | 18 | Source http://sunsite.tut.fi/rec/riku/soccer_data/tab/93_94/table.eng0.01_02.html 19 | Team P W L D F A Pts 20 | 1. Arsenal 38 26 9 3 79 - 36 87 21 | 2. Liverpool 38 24 8 6 67 - 30 80 22 | 3. Manchester_U 38 24 5 9 87 - 45 77 23 | 4. Newcastle 38 21 8 9 74 - 52 71 24 | 5. Leeds 38 18 12 8 53 - 37 66 25 | 6. Chelsea 38 17 13 8 66 - 38 64 26 | 7. West_Ham 38 15 8 15 48 - 57 53 27 | 8. Aston_Villa 38 12 14 12 46 - 47 50 28 | 9. Tottenham 38 14 8 16 49 - 53 50 29 | 10. Blackburn 38 12 10 16 55 - 51 46 30 | 11. Southampton 38 12 9 17 46 - 54 45 31 | 12. Middlesbrough 38 12 9 17 35 - 47 45 32 | 13. Fulham 38 10 14 14 36 - 44 44 33 | 14. Charlton 38 10 14 14 38 - 49 44 34 | 15. Everton 38 11 10 17 45 - 57 43 35 | 16. Bolton 38 9 13 16 44 - 62 40 36 | 17. Sunderland 38 10 10 18 29 - 51 40 37 | ------------------------------------------------------- 38 | 18. Ipswich 38 9 9 20 41 - 64 36 39 | 19. Derby 38 8 6 24 33 - 63 30 40 | 20. Leicester 38 5 13 20 30 - 64 28 41 | 42 | -------------------------------------------------------------------------------- /src/conf/checkstyle.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # http://checkstyle.sf.net/config_javadoc.html 17 | checkstyle.javadoc.scope = public 18 | checkstyle.require.packagehtml = true 19 | checkstyle.require.version = false 20 | checkstyle.allow.noauthor = true 21 | 22 | # http://checkstyle.sf.net/config_naming.html 23 | checkstyle.pattern.const = ^[A-Z](_?[A-Z0-9]+)*$ 24 | checkstyle.pattern.static = ^[a-z][a-zA-Z0-9]*$ 25 | checkstyle.pattern.parameter = ^[a-z][a-zA-Z0-9]*$ 26 | checkstyle.pattern.package = ^[a-z]+(\.[a-z][a-z0-9]*)*$ 27 | checkstyle.pattern.type = ^[A-Z][a-zA-Z0-9]*$ 28 | checkstyle.pattern.method = ^[a-z][a-zA-Z0-9]*$ 29 | checkstyle.pattern.localvar = ^[a-z][a-zA-Z0-9]*$ 30 | checkstyle.pattern.localfinalvar = ^[a-z][a-zA-Z0-9]*$ 31 | 32 | # http://checkstyle.sf.net/config_header.html 33 | checkstyle.header.ignore.line = 1,2,3,4,5,6 34 | 35 | # http://checkstyle.sf.net/config_import.html 36 | checkstyle.illegal.imports = sun,com 37 | 38 | # http://checkstyle.sf.net/config_sizes.html 39 | checkstyle.maxlinelen = 120 40 | # be overly strict here for while 41 | checkstyle.maxmethodlen = 25 42 | checkstyle.maxconstructorlen = 25 43 | checkstyle.maxfilelen = 200 44 | checkstyle.maxparameters = 4 45 | 46 | # http://checkstyle.sf.net/config_whitespace.html 47 | checkstyle.allow.tabs = false 48 | checkstyle.ignore.whitespace = true 49 | checkstyle.paren.pad = nopad 50 | checkstyle.wrap.operator = eol 51 | 52 | # http://checkstyle.sf.net/config_modifiers.html 53 | checkstyle.pattern.publicmember = ^$ 54 | 55 | # http://checkstyle.sf.net/config_blocks.html 56 | checkstyle.block.try = stmt 57 | checkstyle.block.catch = stmt 58 | checkstyle.block.finally = stmt 59 | checkstyle.lcurly.type = eol 60 | checkstyle.lcurly.method = eol 61 | checkstyle.lcurly.other = eol 62 | checkstyle.rcurly = same 63 | 64 | # http://checkstyle.sf.net/config_misc.html 65 | checkstyle.illegal.instantiations = java.lang.Boolean,java.lang.String 66 | -------------------------------------------------------------------------------- /src/conf/jdepend.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # http://www.clarkware.com/software/JDepend.html 17 | 18 | # ignore JDK classes for dependency purposes 19 | ignore.java=java.* 20 | 21 | # in theory, the following lines should be sufficient, but don't seem to have any effect 22 | java.lang=0 23 | java.io=0 24 | java.util=0 25 | -------------------------------------------------------------------------------- /src/site/resources/download_functor.cgi: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Just call the standard mirrors.cgi script. It will use download.html 3 | # as the input template. 4 | exec /www/www.apache.org/dyn/mirrors/mirrors.cgi $* -------------------------------------------------------------------------------- /src/site/resources/images/functor-logo-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-functor/9552c00ea3741c2240f3bea9d48ea9ea2fa53ec4/src/site/resources/images/functor-logo-white.png -------------------------------------------------------------------------------- /src/site/resources/images/functor-logo-white.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-functor/9552c00ea3741c2240f3bea9d48ea9ea2fa53ec4/src/site/resources/images/functor-logo-white.xcf -------------------------------------------------------------------------------- /src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | Commons Functor 21 | /images/functor-logo-white.png 22 | /index.html 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/site/xdoc/building.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | Building 21 | Apache Commons Development Team 22 | Rodney Waldhoff 23 | 24 | 25 | 26 |
27 |

28 | To build Commons Functor from scratch, you must first obtain the source, 29 | from 30 | the SVN server. 31 |

32 |

33 | In order to build Commons Functor you will need Maven. 34 | Install a recent Maven release. 35 | 42 |

43 |

44 | With Maven installed, you should be able to run an arbitrary maven goal from the root Commons Functor 45 | directory. Commonly used goals include 46 | clean, test, compile, package, install and site. 47 |

48 |
49 | 50 |
51 | --------------------------------------------------------------------------------