├── .github └── workflows │ └── maven.yml ├── .gitignore ├── LICENSE.txt ├── README.md ├── pom.xml ├── scripts └── mkzip.sh └── src ├── main ├── java │ └── org │ │ └── javimmutable │ │ └── collections │ │ ├── Computation.java │ │ ├── Func0.java │ │ ├── Func0Throws.java │ │ ├── Func1.java │ │ ├── Func1Throws.java │ │ ├── Func2.java │ │ ├── Func2Throws.java │ │ ├── Func3.java │ │ ├── Func3Throws.java │ │ ├── Func4.java │ │ ├── Func4Throws.java │ │ ├── GenericCollector.java │ │ ├── IArray.java │ │ ├── IArrayBuilder.java │ │ ├── IArrays.java │ │ ├── ICollection.java │ │ ├── ICollectors.java │ │ ├── IDeque.java │ │ ├── IDequeBuilder.java │ │ ├── IDeques.java │ │ ├── IList.java │ │ ├── IListBuilder.java │ │ ├── IListMap.java │ │ ├── IListMaps.java │ │ ├── ILists.java │ │ ├── IMap.java │ │ ├── IMapBuilder.java │ │ ├── IMapEntry.java │ │ ├── IMaps.java │ │ ├── IMultiset.java │ │ ├── IMultisets.java │ │ ├── ISet.java │ │ ├── ISetBuilder.java │ │ ├── ISetMap.java │ │ ├── ISetMaps.java │ │ ├── ISets.java │ │ ├── IStreamable.java │ │ ├── Indexed.java │ │ ├── IndexedProc1.java │ │ ├── IndexedProc1Throws.java │ │ ├── IntFunc2.java │ │ ├── InvariantCheckable.java │ │ ├── MapEntry.java │ │ ├── Mapped.java │ │ ├── Maybe.java │ │ ├── NotNull.java │ │ ├── Proc0.java │ │ ├── Proc0Throws.java │ │ ├── Proc1.java │ │ ├── Proc1Throws.java │ │ ├── Proc2.java │ │ ├── Proc2Throws.java │ │ ├── Result.java │ │ ├── SplitIterator.java │ │ ├── SplitableIterable.java │ │ ├── SplitableIterator.java │ │ ├── Sum1.java │ │ ├── Sum1Throws.java │ │ ├── Sum2.java │ │ ├── Sum2Throws.java │ │ ├── Temp.java │ │ ├── Tuple2.java │ │ ├── Tuple3.java │ │ ├── Tuple4.java │ │ ├── array │ │ ├── ArrayAssignMapper.java │ │ ├── ArrayContainsMapper.java │ │ ├── ArrayDeleteMapper.java │ │ ├── ArrayFindEntryMapper.java │ │ ├── ArrayGetMapper.java │ │ ├── ArrayIterationMapper.java │ │ ├── ArraySizeMapper.java │ │ ├── ArrayUpdateMapper.java │ │ ├── TrieArray.java │ │ ├── TrieArrayBuilder.java │ │ ├── TrieArrayNode.java │ │ └── TrieLongArrayNode.java │ │ ├── common │ │ ├── AbstractMap.java │ │ ├── AbstractMultiset.java │ │ ├── AbstractSet.java │ │ ├── AbstractSetUsingMap.java │ │ ├── ArrayHelper.java │ │ ├── ArrayToMapAdaptor.java │ │ ├── BitmaskMath.java │ │ ├── CollisionMap.java │ │ ├── CollisionSet.java │ │ ├── Conditions.java │ │ ├── DequeListAdaptor.java │ │ ├── ExpectedOrderSorter.java │ │ ├── GenericSetBuilder.java │ │ ├── IntArrayMappedTrieMath.java │ │ ├── ListAdaptor.java │ │ ├── LongArrayMappedTrieMath.java │ │ ├── MapAdaptor.java │ │ ├── MutableDelta.java │ │ ├── SetAdaptor.java │ │ ├── StreamConstants.java │ │ ├── Subindexed.java │ │ └── ToStringHelper.java │ │ ├── deque │ │ ├── ArrayDeque.java │ │ ├── BranchNode.java │ │ ├── DequeHelper.java │ │ ├── EmptyNode.java │ │ ├── ForwardBuilder.java │ │ ├── LeafNode.java │ │ ├── Node.java │ │ └── ReverseBuilder.java │ │ ├── hash │ │ ├── EmptyHashMap.java │ │ ├── EmptyHashSet.java │ │ ├── HashMap.java │ │ ├── HashMultiset.java │ │ ├── HashSet.java │ │ ├── HashSetBuilder.java │ │ ├── TimingLoop.java │ │ ├── map │ │ │ ├── ArrayMapNode.java │ │ │ ├── ArrayMultiValueMapNode.java │ │ │ └── ArraySingleValueMapNode.java │ │ └── set │ │ │ ├── ArrayMultiValueSetNode.java │ │ │ ├── ArraySetNode.java │ │ │ └── ArraySingleValueSetNode.java │ │ ├── indexed │ │ ├── IndexedArray.java │ │ ├── IndexedHelper.java │ │ └── IndexedList.java │ │ ├── inorder │ │ ├── OrderedMap.java │ │ ├── OrderedMultiset.java │ │ └── OrderedSet.java │ │ ├── iterators │ │ ├── AbstractSplitableIterator.java │ │ ├── EmptyIterator.java │ │ ├── EntryStreamable.java │ │ ├── GenericIterator.java │ │ ├── IndexedIterator.java │ │ ├── IteratorHelper.java │ │ ├── LazyMultiIterator.java │ │ ├── SimpleTransformIterator.java │ │ ├── SingleValueIterator.java │ │ ├── TransformIterator.java │ │ └── TransformStreamable.java │ │ ├── list │ │ ├── AbstractNode.java │ │ ├── BranchNode.java │ │ ├── EmptyNode.java │ │ ├── ListAppendTimingComparison.java │ │ ├── ListCollisionMap.java │ │ ├── ListCollisionSet.java │ │ ├── ListTimingComparison.java │ │ ├── MultiValueNode.java │ │ ├── OneValueNode.java │ │ ├── RAListTimingComparison.java │ │ ├── TreeBuilder.java │ │ └── TreeList.java │ │ ├── listmap │ │ ├── AbstractListMap.java │ │ ├── HashListMap.java │ │ ├── ListMapTimingLoop.java │ │ ├── OrderedListMap.java │ │ └── TreeListMap.java │ │ ├── package-info.java │ │ ├── serialization │ │ ├── AbstractListMapProxy.java │ │ ├── AbstractListProxy.java │ │ ├── AbstractMapProxy.java │ │ ├── AbstractMultisetProxy.java │ │ ├── AbstractSetMapProxy.java │ │ ├── AbstractSetProxy.java │ │ ├── ArrayDequeProxy.java │ │ ├── ArrayProxy.java │ │ ├── HashListMapProxy.java │ │ ├── HashMapProxy.java │ │ ├── HashMultisetProxy.java │ │ ├── HashSetMapProxy.java │ │ ├── HashSetProxy.java │ │ ├── MaybeProxy.java │ │ ├── NotNullProxy.java │ │ ├── OrderedListMapProxy.java │ │ ├── OrderedMapProxy.java │ │ ├── OrderedMultisetProxy.java │ │ ├── OrderedSetMapProxy.java │ │ ├── OrderedSetProxy.java │ │ ├── TemplateSetMapProxy.java │ │ ├── TreeListMapProxy.java │ │ ├── TreeListProxy.java │ │ ├── TreeMapProxy.java │ │ ├── TreeMultisetProxy.java │ │ ├── TreeSetMapProxy.java │ │ └── TreeSetProxy.java │ │ ├── setmap │ │ ├── AbstractSetMap.java │ │ ├── HashSetMap.java │ │ ├── OrderedSetMap.java │ │ ├── SetMapFactory.java │ │ ├── TemplateSetMap.java │ │ └── TreeSetMap.java │ │ ├── tree │ │ ├── AbstractNode.java │ │ ├── ComparableComparator.java │ │ ├── FringeNode.java │ │ ├── LeafNode.java │ │ ├── TimingComparison.java │ │ ├── TreeCollisionMap.java │ │ ├── TreeCollisionSet.java │ │ ├── TreeMap.java │ │ ├── TreeMapBuilder.java │ │ ├── TreeMultiset.java │ │ ├── TreeSet.java │ │ └── ValueNode.java │ │ └── util │ │ ├── Functions.java │ │ ├── MapAccessTimingComparison.java │ │ ├── MapTimingComparison.java │ │ └── Zip.java └── resources │ └── LICENSE.txt ├── site └── markdown │ └── index.md └── test ├── java └── org │ └── javimmutable │ └── collections │ ├── ComputationTest.java │ ├── ICollectorsTest.java │ ├── MaybeTest.java │ ├── NotNullTest.java │ ├── ReadmeTest.java │ ├── ResultTest.java │ ├── SplitableIterableTest.java │ ├── StaticConstructorsTest.java │ ├── Tuple2Test.java │ ├── Tuple3Test.java │ ├── Tuple4Test.java │ ├── array │ ├── TrieArrayNodeTest.java │ ├── TrieArrayTest.java │ └── TrieLongArrayNodeTest.java │ ├── common │ ├── ArrayHelperTest.java │ ├── BitmaskMathTest.java │ ├── Checked.java │ ├── IntArrayMappedTrieMathTest.java │ ├── LongArrayMappedTrieMathTest.java │ ├── MapBuilderTestAdapter.java │ ├── SetBuilderTestAdapter.java │ ├── StandardBuilderTests.java │ ├── StandardCollisionMapTests.java │ ├── StandardCollisionSetTests.java │ ├── StandardDequeTests.java │ ├── StandardListTests.java │ ├── StandardMapTests.java │ ├── StandardMultisetTests.java │ ├── StandardSerializableTests.java │ ├── StandardSetTests.java │ ├── StandardStreamableTests.java │ └── TestUtil.java │ ├── deque │ ├── ArrayDequeTest.java │ ├── BranchNodeTest.java │ ├── BuilderTestAdapter.java │ ├── ForwardBuilderTest.java │ ├── LeafNodeTest.java │ └── ReverseBuilderTest.java │ ├── hash │ ├── EmptyHashMapTest.java │ ├── HashMapTest.java │ ├── HashMultisetTest.java │ └── HashSetTest.java │ ├── indexed │ ├── IndexedArrayTest.java │ └── IndexedHelperTest.java │ ├── inorder │ ├── OrderedMapTest.java │ ├── OrderedMultisetTest.java │ └── OrderedSetTest.java │ ├── iterators │ ├── GenericIteratorTest.java │ ├── IndexedIteratorTest.java │ ├── IteratorHelperTest.java │ ├── LazyMultiIteratorTest.java │ ├── ListCombinations.java │ ├── ListCombinationsTest.java │ ├── StandardIteratorTests.java │ └── TransformIteratorTest.java │ ├── list │ ├── BranchNodeTest.java │ ├── BuilderTestAdapter.java │ ├── EmptyNodeTest.java │ ├── IteratorTest.java │ ├── ListCollisionMapTest.java │ ├── ListCollisionSetTest.java │ ├── MultiValueNodeTest.java │ ├── OneValueNodeTest.java │ ├── TreeBuilderTest.java │ └── TreeListTest.java │ ├── listmap │ ├── AbstractListMapTestCase.java │ ├── HashListMapTest.java │ ├── OrderedListMapTest.java │ └── TreeListMapTest.java │ ├── serialization │ └── TuplesTest.java │ ├── setmap │ ├── AbstractSetMapTestCase.java │ ├── HashSetMapTest.java │ ├── OrderedSetMapTest.java │ ├── TemplateSetMapTest.java │ └── TreeSetMapTest.java │ ├── stress_test │ ├── AbstractMapStressTestable.java │ ├── AbstractSetStressTestable.java │ ├── AbstractStressTestableTest.java │ ├── ArrayIndexRange.java │ ├── ArrayStressTester.java │ ├── DequeStressTester.java │ ├── IterationOrder.java │ ├── KeyFactory.java │ ├── KeyWrapper.java │ ├── ListMapStressTester.java │ ├── ListStressTester.java │ ├── MapStressTester.java │ ├── MultisetStressTester.java │ ├── RandomKeyManager.java │ ├── RandomKeyManagerTest.java │ ├── RunStressTests.java │ ├── SetMapStressTester.java │ ├── SetStressTester.java │ ├── SizeStepListFactory.java │ ├── SizeStepListFactoryTest.java │ ├── StressTestUtil.java │ └── StressTester.java │ ├── tree │ ├── ComparableComparatorTest.java │ ├── LeafNodeTest.java │ ├── TreeCollisionMapTest.java │ ├── TreeCollisionSetTest.java │ ├── TreeMapBuilderTest.java │ ├── TreeMapTest.java │ ├── TreeMultisetTest.java │ ├── TreeSetTest.java │ └── ValueNodeTest.java │ └── util │ ├── FunctionsTest.java │ └── ZipTest.java └── resources └── LICENSE.txt /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven 3 | 4 | name: Java CI with Maven 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v4 19 | - uses: actions/setup-java@v4 20 | with: 21 | distribution: 'corretto' 22 | java-version: '11' 23 | - name: Build with Maven 24 | run: mvn -B package --file pom.xml 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | out 3 | *~ 4 | _* 5 | target 6 | collections.iml 7 | javimmutable-collections.iml 8 | javimmutable-collections.ipr 9 | javimmutable-collections.iws 10 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Burton Computer Corporation 2 | http://www.burton-computer.com 3 | 4 | Copyright (c) 2023, Burton Computer Corporation 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are 9 | met: 10 | 11 | Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the 17 | distribution. 18 | 19 | Neither the name of the Burton Computer Corporation nor the names 20 | of its contributors may be used to endorse or promote products 21 | derived from this software without specific prior written 22 | permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | -------------------------------------------------------------------------------- /scripts/mkzip.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -d target/checkout/target ] ; then 4 | cd target/checkout/target 5 | else 6 | mvn clean package 7 | cd target || exit 1 8 | fi 9 | [ -f javimmutable-collections-*-sources.jar ] || exit 1 10 | 11 | base=`basename javimmutable-collections-*-sources.jar -sources.jar` 12 | echo $base 13 | 14 | [ -d $base ] && /bin/rm -rf $base 15 | mkdir $base 16 | cp *.jar $base 17 | cp ../LICENSE.txt $base 18 | zip -r ${base}.zip $base 19 | echo created $PWD/${base}.zip 20 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/Func0.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | /** 39 | * Interface for functions that take no arguments and return a value of type T. 40 | * 41 | * @param 42 | */ 43 | @FunctionalInterface 44 | public interface Func0 45 | { 46 | T apply(); 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/Func0Throws.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | /** 39 | * Interface for functions that take no arguments and return a value of type T and might 40 | * throw an exception. 41 | */ 42 | @FunctionalInterface 43 | public interface Func0Throws 44 | { 45 | T apply() 46 | throws E; 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/Func1.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | import java.util.function.Function; 39 | 40 | /** 41 | * Interface for functions that take a single parameter. 42 | */ 43 | @FunctionalInterface 44 | public interface Func1 45 | extends Function 46 | { 47 | R apply(P value); 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/Func1Throws.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | /** 39 | * Interface for functions that take a single parameter and might 40 | * throw an exception. 41 | */ 42 | @FunctionalInterface 43 | public interface Func1Throws 44 | { 45 | R apply(P value) 46 | throws E; 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/Func2.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | /** 39 | * Interface for functions that take two parameters. 40 | */ 41 | @FunctionalInterface 42 | public interface Func2 43 | { 44 | R apply(P1 p1, 45 | P2 p2); 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/Func2Throws.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | /** 39 | * Interface for functions that take two parameters and might 40 | * throw an exception. 41 | */ 42 | @FunctionalInterface 43 | public interface Func2Throws 44 | { 45 | R apply(P1 p1, 46 | P2 p2) 47 | throws E; 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/Func3.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | /** 39 | * Interface for functions that take three parameters. 40 | */ 41 | @FunctionalInterface 42 | public interface Func3 43 | { 44 | R apply(P1 p1, 45 | P2 p2, 46 | P3 p3); 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/Func3Throws.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | /** 39 | * Interface for functions that take three parameters and might 40 | * throw an exception. 41 | */ 42 | @FunctionalInterface 43 | public interface Func3Throws 44 | { 45 | R apply(P1 p1, 46 | P2 p2, 47 | P3 p3) 48 | throws E; 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/Func4.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | /** 39 | * Interface for functions that take four parameters. 40 | */ 41 | @FunctionalInterface 42 | public interface Func4 43 | { 44 | R apply(P1 p1, 45 | P2 p2, 46 | P3 p3, 47 | P4 p4); 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/Func4Throws.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | /** 39 | * Interface for functions that take four parameters and might 40 | * throw an exception. 41 | */ 42 | @FunctionalInterface 43 | public interface Func4Throws 44 | { 45 | R apply(P1 p1, 46 | P2 p2, 47 | P3 p3, 48 | P4 p4) 49 | throws E; 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/ICollection.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | import javax.annotation.Nonnull; 39 | import java.io.Serializable; 40 | import java.util.Iterator; 41 | 42 | public interface ICollection 43 | extends IStreamable, 44 | Serializable 45 | { 46 | /** 47 | * Add value to the container in some manner appropriate to the implementation. 48 | */ 49 | @Nonnull 50 | ICollection insert(T value); 51 | 52 | /** 53 | * Add all values to the container in some manner appropriate to the implementation. 54 | */ 55 | @Nonnull 56 | ICollection insertAll(@Nonnull Iterator iterator); 57 | 58 | /** 59 | * Add all values to the container in some manner appropriate to the implementation. 60 | */ 61 | @Nonnull 62 | ICollection insertAll(@Nonnull Iterable iterable); 63 | 64 | /** 65 | * @return number of values in the collection 66 | */ 67 | int size(); 68 | 69 | /** 70 | * @return true only if collection contains no values 71 | */ 72 | default boolean isEmpty() 73 | { 74 | return size() == 0; 75 | } 76 | 77 | /** 78 | * @return false only if collection contains no values 79 | */ 80 | default boolean isNonEmpty() 81 | { 82 | return !isEmpty(); 83 | } 84 | 85 | /** 86 | * @return an equivalent collection with no values 87 | */ 88 | @Nonnull 89 | ICollection deleteAll(); 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/IListMaps.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | import org.javimmutable.collections.listmap.HashListMap; 39 | import org.javimmutable.collections.listmap.OrderedListMap; 40 | import org.javimmutable.collections.listmap.TreeListMap; 41 | 42 | import javax.annotation.Nonnull; 43 | import java.util.Comparator; 44 | 45 | public final class IListMaps 46 | { 47 | private IListMaps() 48 | { 49 | } 50 | 51 | /** 52 | * Creates a list map with higher performance but no specific ordering of keys. 53 | */ 54 | @Nonnull 55 | public static IListMap hashed() 56 | { 57 | return HashListMap.of(); 58 | } 59 | 60 | /** 61 | * Creates a list map with keys sorted by order they are inserted. 62 | */ 63 | @Nonnull 64 | public static IListMap ordered() 65 | { 66 | return OrderedListMap.of(); 67 | } 68 | 69 | /** 70 | * Creates a list map with keys sorted by their natural ordering. 71 | */ 72 | @Nonnull 73 | public static , V> IListMap sorted() 74 | { 75 | return TreeListMap.of(); 76 | } 77 | 78 | /** 79 | * Creates a list map with keys sorted by the specified Comparator. The Comparator MUST BE IMMUTABLE. 80 | */ 81 | @Nonnull 82 | public static IListMap sorted(@Nonnull Comparator comparator) 83 | { 84 | return TreeListMap.of(comparator); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/IMapEntry.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | import javax.annotation.Nonnull; 39 | import javax.annotation.concurrent.Immutable; 40 | import java.util.Map; 41 | 42 | /** 43 | * An immutable entry in the map. Contains the key and value for that entry. 44 | * key must not be null but value can be null. 45 | */ 46 | @Immutable 47 | public 48 | interface IMapEntry 49 | { 50 | @Nonnull 51 | static IMapEntry of(@Nonnull Map.Entry entry) 52 | { 53 | return new MapEntry(entry); 54 | } 55 | 56 | @Nonnull 57 | static IMapEntry of(@Nonnull IMapEntry entry) 58 | { 59 | return new MapEntry(entry); 60 | } 61 | 62 | @Nonnull 63 | static IMapEntry of(@Nonnull K key, 64 | V value) 65 | { 66 | return new MapEntry(key, value); 67 | } 68 | 69 | @Nonnull 70 | K getKey(); 71 | 72 | V getValue(); 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/IStreamable.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | import javax.annotation.Nonnull; 39 | import java.util.Spliterator; 40 | import java.util.stream.Stream; 41 | import java.util.stream.StreamSupport; 42 | 43 | /** 44 | * Interface for classes that can produce java.util.Streams and are also Iterable. The default stream 45 | * creation implementations use spliterator(). 46 | */ 47 | public interface IStreamable 48 | extends SplitableIterable 49 | { 50 | /** 51 | * Overridden here to require implementations to return a SplitableIterator rather than 52 | * a basic Iterator. This is necessary to allow composition of new objects from methods 53 | * like keys() and values(). 54 | */ 55 | @Nonnull 56 | @Override 57 | SplitableIterator iterator(); 58 | 59 | /** 60 | * @return characteristics value used when creating Spliterators 61 | */ 62 | int getSpliteratorCharacteristics(); 63 | 64 | /** 65 | * Default implementation that creates a Spliterator from a newly created Iterator. 66 | */ 67 | @Nonnull 68 | @Override 69 | default Spliterator spliterator() 70 | { 71 | return iterator().spliterator(getSpliteratorCharacteristics()); 72 | } 73 | 74 | @Nonnull 75 | default Stream stream() 76 | { 77 | return StreamSupport.stream(spliterator(), false); 78 | } 79 | 80 | @Nonnull 81 | default Stream parallelStream() 82 | { 83 | return StreamSupport.stream(spliterator(), true); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/IndexedProc1.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | /** 39 | * Interface for lambdas that accept an integer index plus 1 parameter and return nothing. 40 | */ 41 | @FunctionalInterface 42 | public interface IndexedProc1 43 | { 44 | void apply(int index, 45 | A a); 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/IndexedProc1Throws.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | /** 39 | * Interface for lambdas that accept an integer index plus 1 parameter and return nothing 40 | * but might throw an exception. 41 | */ 42 | @FunctionalInterface 43 | public interface IndexedProc1Throws 44 | { 45 | void apply(int index, 46 | A a) 47 | throws E; 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/IntFunc2.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | @FunctionalInterface 39 | public interface IntFunc2 40 | { 41 | R apply(int p1, 42 | int p2); 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/InvariantCheckable.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | /** 39 | * Implemented by all classes for testing purposes. Base class checks its 40 | * invariants and throws an exception if any of the checks fail. 41 | */ 42 | public interface InvariantCheckable 43 | { 44 | /** 45 | * Checks invariants of implementing class. 46 | */ 47 | void checkInvariants(); 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/Proc0.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | /** 39 | * Interface for lambdas that accept no parameter and return nothing. 40 | */ 41 | @FunctionalInterface 42 | public interface Proc0 43 | { 44 | void apply(); 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/Proc0Throws.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | /** 39 | * Interface for lambdas that accept 1 parameter and return nothing but might throw an exception. 40 | */ 41 | @FunctionalInterface 42 | public interface Proc0Throws 43 | { 44 | void apply() 45 | throws E; 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/Proc1.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | /** 39 | * Interface for lambdas that accept 1 parameter and return nothing. 40 | */ 41 | @FunctionalInterface 42 | public interface Proc1 43 | { 44 | void apply(A a); 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/Proc1Throws.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | /** 39 | * Interface for lambdas that accept 1 parameter and return nothing but might throw an exception. 40 | */ 41 | @FunctionalInterface 42 | public interface Proc1Throws 43 | { 44 | void apply(A a) 45 | throws E; 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/Proc2.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | /** 39 | * Interface for lambdas that accept 2 parameters and return nothing. 40 | */ 41 | @FunctionalInterface 42 | public interface Proc2 43 | { 44 | void apply(A a, 45 | B b); 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/Proc2Throws.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | /** 39 | * Interface for lambdas that accept 2 parameters and return nothing but might throw an exception. 40 | */ 41 | @FunctionalInterface 42 | public interface Proc2Throws 43 | { 44 | void apply(A a, 45 | B b) 46 | throws E; 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/Sum1.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | /** 39 | * Interface for lambdas that accept a result parameter and a value parameter and return 40 | * a value of the same type as the result parameter. 41 | * 42 | * @param value type 43 | * @param result type 44 | */ 45 | @FunctionalInterface 46 | public interface Sum1 47 | { 48 | R apply(R sum, 49 | A a); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/Sum1Throws.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | /** 39 | * Interface for lambdas that accept a result parameter and 1 value parameter and return 40 | * a value of the same type as the result parameter or might throw an exception. 41 | * 42 | * @param value type 43 | * @param result type 44 | */ 45 | @FunctionalInterface 46 | public interface Sum1Throws 47 | { 48 | R apply(R sum, 49 | A a) 50 | throws E; 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/Sum2.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | /** 39 | * Interface for lambdas that accept a result parameter and 2 value parameters and return 40 | * a value of the same type as the result parameter. 41 | * 42 | * @param value type 43 | * @param result type 44 | */ 45 | @FunctionalInterface 46 | public interface Sum2 47 | { 48 | R apply(R sum, 49 | A a, 50 | B b); 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/Sum2Throws.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | /** 39 | * Interface for lambdas that accept a result parameter and 2 value parameters and return 40 | * a value of the same type as the result parameter or might throw an exception. 41 | * 42 | * @param value type 43 | * @param result type 44 | */ 45 | @FunctionalInterface 46 | public interface Sum2Throws 47 | { 48 | R apply(R sum, 49 | A a, 50 | B b) 51 | throws E; 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/array/ArrayAssignMapper.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.array; 37 | 38 | import javax.annotation.Nonnull; 39 | 40 | public interface ArrayAssignMapper 41 | extends ArraySizeMapper 42 | { 43 | /** 44 | * Called during assign operation to create a new mapping 45 | * for the given key and value. 46 | * 47 | * @param key key being assigned to 48 | * @param value value being assigned 49 | * @return non-null mapping 50 | */ 51 | @Nonnull 52 | T mappedAssign(@Nonnull K key, 53 | V value); 54 | 55 | /** 56 | * Called during assign operation to replace an existing mapping 57 | * for the given key and value. 58 | * 59 | * @param current mapping to be replaced 60 | * @param key key being assigned to 61 | * @param value value being assigned 62 | * @return same to keep mapping or non-null to replace mapping 63 | */ 64 | @Nonnull 65 | T mappedAssign(@Nonnull T current, 66 | @Nonnull K key, 67 | V value); 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/array/ArrayContainsMapper.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.array; 37 | 38 | import javax.annotation.Nonnull; 39 | 40 | public interface ArrayContainsMapper 41 | { 42 | boolean mappedContains(@Nonnull T mapping, 43 | @Nonnull K key); 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/array/ArrayDeleteMapper.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.array; 37 | 38 | import javax.annotation.Nonnull; 39 | import javax.annotation.Nullable; 40 | 41 | public interface ArrayDeleteMapper 42 | extends ArraySizeMapper 43 | { 44 | /** 45 | * Called during delete operation to delete a key from a mapping. 46 | * 47 | * @param current mapping to be replaced 48 | * @param key key being deleted 49 | * @return null to remove mapping, same to keep mapping, or non-null to replace mapping 50 | */ 51 | @Nullable 52 | T mappedDelete(@Nonnull T current, 53 | @Nonnull K key); 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/array/ArrayFindEntryMapper.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.array; 37 | 38 | import org.javimmutable.collections.IMapEntry; 39 | import org.javimmutable.collections.Maybe; 40 | 41 | import javax.annotation.Nonnull; 42 | 43 | public interface ArrayFindEntryMapper 44 | extends ArrayGetMapper 45 | { 46 | @Nonnull 47 | Maybe> mappedFindEntry(@Nonnull T mapping, 48 | @Nonnull K key); 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/array/ArrayGetMapper.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.array; 37 | 38 | import org.javimmutable.collections.Maybe; 39 | 40 | import javax.annotation.Nonnull; 41 | 42 | public interface ArrayGetMapper 43 | { 44 | V mappedGetValueOr(@Nonnull T mapping, 45 | @Nonnull K key, 46 | V defaultValue); 47 | 48 | @Nonnull 49 | Maybe mappedFind(@Nonnull T mapping, 50 | @Nonnull K key); 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/array/ArrayIterationMapper.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.array; 37 | 38 | import org.javimmutable.collections.IMapEntry; 39 | import org.javimmutable.collections.iterators.GenericIterator; 40 | 41 | import javax.annotation.Nonnull; 42 | 43 | public interface ArrayIterationMapper 44 | { 45 | @Nonnull 46 | GenericIterator.Iterable mappedKeys(@Nonnull T mapping); 47 | 48 | @Nonnull 49 | GenericIterator.Iterable mappedValues(@Nonnull T mapping); 50 | 51 | @Nonnull 52 | GenericIterator.Iterable> mappedEntries(@Nonnull T mapping); 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/array/ArraySizeMapper.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.array; 37 | 38 | import javax.annotation.Nonnull; 39 | 40 | public interface ArraySizeMapper 41 | { 42 | /** 43 | * Called to obtain number of keys in a given mapping. 44 | * 45 | * @param mapping mapping to be sized 46 | * @return number of keys in the mapping 47 | */ 48 | int mappedSize(@Nonnull T mapping); 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/array/ArrayUpdateMapper.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.array; 37 | 38 | import org.javimmutable.collections.Func1; 39 | import org.javimmutable.collections.Maybe; 40 | 41 | import javax.annotation.Nonnull; 42 | 43 | public interface ArrayUpdateMapper 44 | extends ArrayAssignMapper 45 | { 46 | @Nonnull 47 | T mappedUpdate(@Nonnull T current, 48 | @Nonnull K key, 49 | @Nonnull Func1, V> generator); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/common/Conditions.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.common; 37 | 38 | /** 39 | * Utility class containing static methods for implementing pre and post conditions. 40 | */ 41 | public final class Conditions 42 | { 43 | private Conditions() 44 | { 45 | // prevent class being instantiated 46 | } 47 | 48 | public static void stopNull(Object a) 49 | { 50 | if (a == null) { 51 | throw new NullPointerException(); 52 | } 53 | } 54 | 55 | public static void stopNull(Object a, 56 | Object b) 57 | { 58 | if ((a == null) || (b == null)) { 59 | throw new NullPointerException(); 60 | } 61 | } 62 | 63 | public static void stopNull(Object a, 64 | Object b, 65 | Object c) 66 | { 67 | if ((a == null) || (b == null) || (c == null)) { 68 | throw new NullPointerException(); 69 | } 70 | } 71 | 72 | public static void stopNull(Object a, 73 | Object b, 74 | Object c, 75 | Object d) 76 | { 77 | if ((a == null) || (b == null) || (c == null) || (d == null)) { 78 | throw new NullPointerException(); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/common/DequeListAdaptor.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.common; 37 | 38 | import org.javimmutable.collections.IDeque; 39 | 40 | import javax.annotation.Nonnull; 41 | import javax.annotation.concurrent.Immutable; 42 | import java.util.AbstractList; 43 | import java.util.Iterator; 44 | import java.util.List; 45 | import java.util.Spliterator; 46 | 47 | @Immutable 48 | public class DequeListAdaptor 49 | extends AbstractList 50 | implements List 51 | { 52 | private final IDeque list; 53 | 54 | public DequeListAdaptor(@Nonnull IDeque list) 55 | { 56 | this.list = list; 57 | } 58 | 59 | public static DequeListAdaptor of(@Nonnull IDeque list) 60 | { 61 | return new DequeListAdaptor(list); 62 | } 63 | 64 | @Override 65 | public T get(int index) 66 | { 67 | return list.get(index); 68 | } 69 | 70 | @Override 71 | public int size() 72 | { 73 | return list.size(); 74 | } 75 | 76 | @Nonnull 77 | @Override 78 | public Iterator iterator() 79 | { 80 | return list.iterator(); 81 | } 82 | 83 | @Override 84 | public Spliterator spliterator() 85 | { 86 | return list.spliterator(); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/common/GenericSetBuilder.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.common; 37 | 38 | import org.javimmutable.collections.Func1; 39 | import org.javimmutable.collections.IMap; 40 | import org.javimmutable.collections.IMapBuilder; 41 | import org.javimmutable.collections.ISet; 42 | import org.javimmutable.collections.ISetBuilder; 43 | 44 | import javax.annotation.Nonnull; 45 | 46 | public class GenericSetBuilder 47 | implements ISetBuilder 48 | { 49 | private final IMapBuilder mapBuilder; 50 | private final Func1, ISet> setFactory; 51 | 52 | public GenericSetBuilder(IMapBuilder mapBuilder, 53 | Func1, ISet> setFactory) 54 | { 55 | this.mapBuilder = mapBuilder; 56 | this.setFactory = setFactory; 57 | } 58 | 59 | @Nonnull 60 | @Override 61 | public ISet build() 62 | { 63 | return setFactory.apply(mapBuilder.build()); 64 | } 65 | 66 | @Nonnull 67 | @Override 68 | public ISetBuilder clear() 69 | { 70 | mapBuilder.clear(); 71 | return this; 72 | } 73 | 74 | @Override 75 | public int size() 76 | { 77 | return mapBuilder.size(); 78 | } 79 | 80 | @Nonnull 81 | @Override 82 | public ISetBuilder add(T value) 83 | { 84 | mapBuilder.add(value, Boolean.TRUE); 85 | return this; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/common/ListAdaptor.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.common; 37 | 38 | import org.javimmutable.collections.IList; 39 | 40 | import javax.annotation.Nonnull; 41 | import javax.annotation.concurrent.Immutable; 42 | import java.util.AbstractList; 43 | import java.util.Iterator; 44 | import java.util.List; 45 | import java.util.Spliterator; 46 | 47 | /** 48 | * Immutable List implementation backed by a {@link IList}. 49 | */ 50 | @Immutable 51 | public class ListAdaptor 52 | extends AbstractList 53 | implements List 54 | { 55 | private final IList list; 56 | 57 | public ListAdaptor(@Nonnull IList list) 58 | { 59 | this.list = list; 60 | } 61 | 62 | public static ListAdaptor of(@Nonnull IList list) 63 | { 64 | return new ListAdaptor(list); 65 | } 66 | 67 | @Override 68 | public T get(int index) 69 | { 70 | return list.get(index); 71 | } 72 | 73 | @Override 74 | public int size() 75 | { 76 | return list.size(); 77 | } 78 | 79 | @Nonnull 80 | @Override 81 | public Iterator iterator() 82 | { 83 | return list.iterator(); 84 | } 85 | 86 | @Override 87 | public Spliterator spliterator() 88 | { 89 | return list.spliterator(); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/common/MutableDelta.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.common; 37 | 38 | import org.javimmutable.collections.Func1; 39 | 40 | /** 41 | * Mutable object for tracking changes from zero. 42 | */ 43 | public class MutableDelta 44 | implements Func1 45 | { 46 | private int value; 47 | 48 | public void add(int increment) 49 | { 50 | value += increment; 51 | } 52 | 53 | public void subtract(int decrement) 54 | { 55 | value -= decrement; 56 | } 57 | 58 | public int getValue() 59 | { 60 | return value; 61 | } 62 | 63 | @Override 64 | public Integer apply(Integer callerValue) 65 | { 66 | return value + callerValue; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/common/StreamConstants.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.common; 37 | 38 | import java.util.Spliterator; 39 | 40 | public class StreamConstants 41 | { 42 | public static final int SPLITERATOR_ORDERED = Spliterator.IMMUTABLE | Spliterator.ORDERED; 43 | public static final int SPLITERATOR_UNORDERED = Spliterator.IMMUTABLE; 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/common/ToStringHelper.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.common; 37 | 38 | public class ToStringHelper 39 | { 40 | public static void addToString(StringBuilder sb, 41 | int prefixLength, 42 | K key, 43 | V value) 44 | { 45 | if (sb.length() > prefixLength) { 46 | sb.append(","); 47 | } 48 | sb.append("("); 49 | sb.append(key); 50 | sb.append(","); 51 | sb.append(value); 52 | sb.append(")"); 53 | } 54 | 55 | public static void addToString(StringBuilder sb, 56 | int prefixLength, 57 | V value) 58 | { 59 | if (sb.length() > prefixLength) { 60 | sb.append(","); 61 | } 62 | sb.append(value); 63 | } 64 | 65 | public static String arrayToString(V[] values) 66 | { 67 | StringBuilder sb = new StringBuilder("["); 68 | for (V value : values) { 69 | addToString(sb, 1, value); 70 | } 71 | sb.append("]"); 72 | return sb.toString(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/hash/TimingLoop.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.hash; 37 | 38 | import org.javimmutable.collections.IMap; 39 | 40 | import java.util.Random; 41 | 42 | public final class TimingLoop 43 | { 44 | private TimingLoop() 45 | { 46 | } 47 | 48 | public static void main(String[] args) 49 | { 50 | final int maxLoops = 250000; 51 | final int maxKey = 999999999; 52 | final int maxValue = 999999999; 53 | Random random = new Random(1000); 54 | int adds = 0; 55 | int removes = 0; 56 | int gets = 0; 57 | long startPer = System.currentTimeMillis(); 58 | IMap map = HashMap.of(); 59 | for (int i = 1; i <= maxLoops; ++i) { 60 | int command = random.nextInt(8); 61 | if (command <= 1) { 62 | Integer key = random.nextInt(maxKey); 63 | Integer value = random.nextInt(maxValue); 64 | map = map.assign(key, value); 65 | adds += 1; 66 | } else if (command == 2) { 67 | Integer key = random.nextInt(maxKey); 68 | map = map.delete(key); 69 | removes += 1; 70 | } else { 71 | Integer key = random.nextInt(maxKey); 72 | map.find(key); 73 | gets += 1; 74 | } 75 | } 76 | long endPer = System.currentTimeMillis(); 77 | System.out.printf("phm adds %d removes %d gets %d elapsed %d%n", adds, removes, gets, (endPer - startPer)); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/hash/set/ArraySetNode.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.hash.set; 37 | 38 | import org.javimmutable.collections.Proc1; 39 | import org.javimmutable.collections.Proc1Throws; 40 | import org.javimmutable.collections.common.CollisionSet; 41 | import org.javimmutable.collections.iterators.GenericIterator; 42 | 43 | import javax.annotation.Nonnull; 44 | import javax.annotation.Nullable; 45 | 46 | public interface ArraySetNode 47 | { 48 | int size(@Nonnull CollisionSet collisionSet); 49 | 50 | boolean contains(@Nonnull CollisionSet collisionSet, 51 | @Nonnull T value); 52 | 53 | @Nonnull 54 | ArraySetNode insert(@Nonnull CollisionSet collisionSet, 55 | @Nonnull T value); 56 | 57 | @Nullable 58 | ArraySetNode delete(@Nonnull CollisionSet collisionSet, 59 | @Nonnull T value); 60 | 61 | @Nonnull 62 | GenericIterator.Iterable values(@Nonnull CollisionSet collisionSet); 63 | 64 | void forEach(@Nonnull CollisionSet collisionSet, 65 | @Nonnull Proc1 proc); 66 | 67 | void forEachThrows(@Nonnull CollisionSet collisionSet, 68 | @Nonnull Proc1Throws proc) 69 | throws E; 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/iterators/EntryStreamable.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.iterators; 37 | 38 | import org.javimmutable.collections.IMapEntry; 39 | import org.javimmutable.collections.IStreamable; 40 | import org.javimmutable.collections.SplitableIterator; 41 | 42 | import javax.annotation.Nonnull; 43 | 44 | public class EntryStreamable, D extends IStreamable>> 45 | implements IStreamable> 46 | { 47 | private final D source; 48 | 49 | public EntryStreamable(@Nonnull D source) 50 | { 51 | this.source = source; 52 | } 53 | 54 | @Nonnull 55 | @Override 56 | public SplitableIterator> iterator() 57 | { 58 | return LazyMultiIterator.transformed(source.iterator(), e -> () -> TransformIterator.of(e.getValue().iterator(), v -> IMapEntry.of(e.getKey(), v))); 59 | } 60 | 61 | @Override 62 | public int getSpliteratorCharacteristics() 63 | { 64 | return source.getSpliteratorCharacteristics(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/iterators/SimpleTransformIterator.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.iterators; 37 | 38 | import javax.annotation.Nonnull; 39 | import java.util.Iterator; 40 | import java.util.function.Function; 41 | 42 | public class SimpleTransformIterator 43 | implements Iterator 44 | { 45 | private final Iterator source; 46 | private final Function transforminator; 47 | 48 | public SimpleTransformIterator(@Nonnull Iterator source, 49 | @Nonnull Function transforminator) 50 | { 51 | this.source = source; 52 | this.transforminator = transforminator; 53 | } 54 | 55 | public static Iterator of(@Nonnull Iterator source, 56 | @Nonnull Function transforminator) 57 | { 58 | return new SimpleTransformIterator<>(source, transforminator); 59 | } 60 | 61 | @Override 62 | public boolean hasNext() 63 | { 64 | return source.hasNext(); 65 | } 66 | 67 | @Override 68 | public T next() 69 | { 70 | return transforminator.apply(source.next()); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/iterators/SingleValueIterator.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.iterators; 37 | 38 | import org.javimmutable.collections.SplitableIterable; 39 | 40 | import java.util.NoSuchElementException; 41 | 42 | public class SingleValueIterator 43 | extends AbstractSplitableIterator 44 | { 45 | private final T value; 46 | private boolean started; 47 | 48 | private SingleValueIterator(T value) 49 | { 50 | this.value = value; 51 | } 52 | 53 | public static SingleValueIterator of(T value) 54 | { 55 | return new SingleValueIterator<>(value); 56 | } 57 | 58 | public static SplitableIterable iterable(T value) 59 | { 60 | return () -> new SingleValueIterator<>(value); 61 | } 62 | 63 | @Override 64 | public boolean hasNext() 65 | { 66 | return !started; 67 | } 68 | 69 | @Override 70 | public T next() 71 | { 72 | if (started) { 73 | throw new NoSuchElementException(); 74 | } 75 | started = true; 76 | return value; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package contains all of the classes and interfaces intended for public use of the API. 3 | * The project wiki provides extensive documentation on the public classes and interfaces. 4 | *

5 | * Several factory classes provide static methods to create collections: 6 | * 7 | *

    8 | *
  • {@link org.javimmutable.collections.ILists}
  • 9 | *
  • {@link org.javimmutable.collections.IMaps}
  • 10 | *
  • {@link org.javimmutable.collections.ISets}
  • 11 | *
  • {@link org.javimmutable.collections.IDeques}
  • 12 | *
  • {@link org.javimmutable.collections.IArrays}
  • 13 | *
  • {@link org.javimmutable.collections.IMultisets}
  • 14 | *
  • {@link org.javimmutable.collections.IListMaps}
  • 15 | *
  • {@link org.javimmutable.collections.ISetMaps}
  • 16 | *
17 | * 18 | * @see
Project Wiki 19 | */ 20 | package org.javimmutable.collections; 21 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/serialization/HashListMapProxy.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.serialization; 37 | 38 | import org.javimmutable.collections.listmap.HashListMap; 39 | 40 | /** 41 | * Serialization proxy class to safely serialize immutable collection. 42 | */ 43 | @SuppressWarnings("unchecked") 44 | public class HashListMapProxy 45 | extends AbstractListMapProxy 46 | { 47 | private static final long serialVersionUID = -121805; 48 | 49 | public HashListMapProxy() 50 | { 51 | super(HashListMap.of()); 52 | } 53 | 54 | public HashListMapProxy(HashListMap map) 55 | { 56 | super(map); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/serialization/HashMapProxy.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.serialization; 37 | 38 | import org.javimmutable.collections.hash.EmptyHashMap; 39 | import org.javimmutable.collections.hash.HashMap; 40 | 41 | /** 42 | * Serialization proxy class to safely serialize immutable collection. 43 | */ 44 | @SuppressWarnings("rawtypes") 45 | public class HashMapProxy 46 | extends AbstractMapProxy 47 | { 48 | private static final long serialVersionUID = -121805; 49 | 50 | public HashMapProxy() 51 | { 52 | super(HashMap.of()); 53 | } 54 | 55 | public HashMapProxy(HashMap map) 56 | { 57 | super(map); 58 | } 59 | 60 | public HashMapProxy(EmptyHashMap map) 61 | { 62 | super(map); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/serialization/HashMultisetProxy.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.serialization; 37 | 38 | import org.javimmutable.collections.hash.HashMultiset; 39 | 40 | /** 41 | * Serialization proxy class to safely serialize immutable collection. 42 | */ 43 | @SuppressWarnings("unchecked") 44 | public class HashMultisetProxy 45 | extends AbstractMultisetProxy 46 | { 47 | private static final long serialVersionUID = -121805; 48 | 49 | public HashMultisetProxy() 50 | { 51 | super(HashMultiset.of()); 52 | } 53 | 54 | public HashMultisetProxy(HashMultiset set) 55 | { 56 | super(set); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/serialization/HashSetMapProxy.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.serialization; 37 | 38 | import org.javimmutable.collections.setmap.HashSetMap; 39 | 40 | /** 41 | * Serialization proxy class to safely serialize immutable collection. 42 | */ 43 | @SuppressWarnings("unchecked") 44 | public class HashSetMapProxy 45 | extends AbstractSetMapProxy 46 | { 47 | private static final long serialVersionUID = -121805; 48 | 49 | public HashSetMapProxy() 50 | { 51 | super(HashSetMap.of()); 52 | } 53 | 54 | public HashSetMapProxy(HashSetMap map) 55 | { 56 | super(map); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/serialization/HashSetProxy.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.serialization; 37 | 38 | import org.javimmutable.collections.hash.HashSet; 39 | 40 | @SuppressWarnings("rawtypes") 41 | public class HashSetProxy 42 | extends AbstractSetProxy 43 | { 44 | private static final long serialVersionUID = -121805; 45 | 46 | public HashSetProxy() 47 | { 48 | super(HashSet.of()); 49 | } 50 | 51 | public HashSetProxy(HashSet set) 52 | { 53 | super(set); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/serialization/OrderedListMapProxy.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.serialization; 37 | 38 | import org.javimmutable.collections.listmap.OrderedListMap; 39 | 40 | /** 41 | * Serialization proxy class to safely serialize immutable collection. 42 | */ 43 | @SuppressWarnings("unchecked") 44 | public class OrderedListMapProxy 45 | extends AbstractListMapProxy 46 | { 47 | private static final long serialVersionUID = -121805; 48 | 49 | public OrderedListMapProxy() 50 | { 51 | super(OrderedListMap.of()); 52 | } 53 | 54 | public OrderedListMapProxy(OrderedListMap map) 55 | { 56 | super(map); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/serialization/OrderedMapProxy.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.serialization; 37 | 38 | import org.javimmutable.collections.inorder.OrderedMap; 39 | 40 | /** 41 | * Serialization proxy class to safely serialize immutable collection. 42 | */ 43 | @SuppressWarnings("unchecked") 44 | public class OrderedMapProxy 45 | extends AbstractMapProxy 46 | { 47 | private static final long serialVersionUID = -121805; 48 | 49 | public OrderedMapProxy() 50 | { 51 | super(OrderedMap.of()); 52 | } 53 | 54 | public OrderedMapProxy(OrderedMap map) 55 | { 56 | super(map); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/serialization/OrderedMultisetProxy.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.serialization; 37 | 38 | import org.javimmutable.collections.inorder.OrderedMultiset; 39 | 40 | /** 41 | * Serialization proxy class to safely serialize immutable collection. 42 | */ 43 | @SuppressWarnings("unchecked") 44 | public class OrderedMultisetProxy 45 | extends AbstractMultisetProxy 46 | { 47 | private static final long serialVersionUID = -121805; 48 | 49 | public OrderedMultisetProxy() 50 | { 51 | super(OrderedMultiset.of()); 52 | } 53 | 54 | public OrderedMultisetProxy(OrderedMultiset set) 55 | { 56 | super(set); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/serialization/OrderedSetMapProxy.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.serialization; 37 | 38 | import org.javimmutable.collections.setmap.OrderedSetMap; 39 | 40 | /** 41 | * Serialization proxy class to safely serialize immutable collection. 42 | */ 43 | @SuppressWarnings("unchecked") 44 | public class OrderedSetMapProxy 45 | extends AbstractSetMapProxy 46 | { 47 | private static final long serialVersionUID = -121805; 48 | 49 | public OrderedSetMapProxy() 50 | { 51 | super(OrderedSetMap.of()); 52 | } 53 | 54 | public OrderedSetMapProxy(OrderedSetMap map) 55 | { 56 | super(map); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/serialization/OrderedSetProxy.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.serialization; 37 | 38 | import org.javimmutable.collections.inorder.OrderedSet; 39 | 40 | public class OrderedSetProxy 41 | extends AbstractSetProxy 42 | { 43 | private static final long serialVersionUID = -121805; 44 | 45 | public OrderedSetProxy() 46 | { 47 | super(OrderedSet.of()); 48 | } 49 | 50 | public OrderedSetProxy(OrderedSet set) 51 | { 52 | super(set); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/serialization/TreeListMapProxy.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.serialization; 37 | 38 | import org.javimmutable.collections.IListMap; 39 | import org.javimmutable.collections.listmap.TreeListMap; 40 | 41 | import java.io.IOException; 42 | import java.io.ObjectInput; 43 | import java.io.ObjectOutput; 44 | import java.util.Comparator; 45 | 46 | /** 47 | * Serialization proxy class to safely serialize immutable collection. 48 | */ 49 | @SuppressWarnings("unchecked") 50 | public class TreeListMapProxy 51 | extends AbstractListMapProxy 52 | { 53 | private static final long serialVersionUID = -121805; 54 | 55 | public TreeListMapProxy() 56 | { 57 | super(TreeListMap.of()); 58 | } 59 | 60 | public TreeListMapProxy(TreeListMap map) 61 | { 62 | super(map); 63 | } 64 | 65 | @Override 66 | protected IListMap readMap(ObjectInput in) 67 | throws IOException, ClassNotFoundException 68 | { 69 | Comparator comparator = (Comparator)in.readObject(); 70 | return TreeListMap.of(comparator); 71 | } 72 | 73 | @Override 74 | protected void writeMap(ObjectOutput out) 75 | throws IOException 76 | { 77 | TreeListMap treeMap = (TreeListMap)map; 78 | out.writeObject(treeMap.getComparator()); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/serialization/TreeListProxy.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.serialization; 37 | 38 | import org.javimmutable.collections.IListBuilder; 39 | import org.javimmutable.collections.list.TreeList; 40 | 41 | import java.util.function.Supplier; 42 | 43 | /** 44 | * Serialization proxy class to safely serialize immutable collection. 45 | */ 46 | public class TreeListProxy 47 | extends AbstractListProxy 48 | { 49 | private static final Supplier BUILDER_FACTORY = () -> TreeList.listBuilder(); 50 | private static final long serialVersionUID = -121805; 51 | 52 | public TreeListProxy() 53 | { 54 | super(BUILDER_FACTORY, TreeList.of()); 55 | } 56 | 57 | public TreeListProxy(TreeList list) 58 | { 59 | super(BUILDER_FACTORY, list); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/serialization/TreeMapProxy.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.serialization; 37 | 38 | import org.javimmutable.collections.IMap; 39 | import org.javimmutable.collections.tree.TreeMap; 40 | 41 | import java.io.IOException; 42 | import java.io.ObjectInput; 43 | import java.io.ObjectOutput; 44 | import java.util.Comparator; 45 | 46 | /** 47 | * Serialization proxy class to safely serialize immutable collection. 48 | */ 49 | @SuppressWarnings("unchecked") 50 | public class TreeMapProxy 51 | extends AbstractMapProxy 52 | { 53 | private static final long serialVersionUID = -121805; 54 | 55 | public TreeMapProxy() 56 | { 57 | super(TreeMap.of()); 58 | } 59 | 60 | public TreeMapProxy(TreeMap map) 61 | { 62 | super(map); 63 | } 64 | 65 | @Override 66 | protected IMap readMap(ObjectInput in) 67 | throws IOException, ClassNotFoundException 68 | { 69 | Comparator comparator = (Comparator)in.readObject(); 70 | return TreeMap.of(comparator); 71 | } 72 | 73 | @Override 74 | protected void writeMap(ObjectOutput out) 75 | throws IOException 76 | { 77 | TreeMap treeMap = (TreeMap)map; 78 | out.writeObject(treeMap.getComparator()); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/serialization/TreeMultisetProxy.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.serialization; 37 | 38 | import org.javimmutable.collections.IMultiset; 39 | import org.javimmutable.collections.tree.TreeMultiset; 40 | 41 | import java.io.IOException; 42 | import java.io.ObjectInput; 43 | import java.io.ObjectOutput; 44 | import java.util.Comparator; 45 | 46 | /** 47 | * Serialization proxy class to safely serialize immutable collection. 48 | */ 49 | @SuppressWarnings("unchecked") 50 | public class TreeMultisetProxy 51 | extends AbstractMultisetProxy 52 | { 53 | private static final long serialVersionUID = -121805; 54 | 55 | public TreeMultisetProxy() 56 | { 57 | super(TreeMultiset.of()); 58 | } 59 | 60 | public TreeMultisetProxy(TreeMultiset set) 61 | { 62 | super(set); 63 | } 64 | 65 | @Override 66 | protected IMultiset readSet(ObjectInput in) 67 | throws IOException, ClassNotFoundException 68 | { 69 | Comparator comparator = (Comparator)in.readObject(); 70 | return TreeMultiset.of(comparator); 71 | } 72 | 73 | @Override 74 | protected void writeSet(ObjectOutput out) 75 | throws IOException 76 | { 77 | TreeMultiset treeSet = (TreeMultiset)set; 78 | out.writeObject(treeSet.getComparator()); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/serialization/TreeSetMapProxy.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.serialization; 37 | 38 | import org.javimmutable.collections.ISetMap; 39 | import org.javimmutable.collections.setmap.TreeSetMap; 40 | 41 | import java.io.IOException; 42 | import java.io.ObjectInput; 43 | import java.io.ObjectOutput; 44 | import java.util.Comparator; 45 | 46 | /** 47 | * Serialization proxy class to safely serialize immutable collection. 48 | */ 49 | @SuppressWarnings("unchecked") 50 | public class TreeSetMapProxy 51 | extends AbstractSetMapProxy 52 | { 53 | private static final long serialVersionUID = -121805; 54 | 55 | public TreeSetMapProxy() 56 | { 57 | super(TreeSetMap.of()); 58 | } 59 | 60 | public TreeSetMapProxy(TreeSetMap map) 61 | { 62 | super(map); 63 | } 64 | 65 | @Override 66 | protected ISetMap readMap(ObjectInput in) 67 | throws IOException, ClassNotFoundException 68 | { 69 | Comparator comparator = (Comparator)in.readObject(); 70 | return TreeSetMap.of(comparator); 71 | } 72 | 73 | @Override 74 | protected void writeMap(ObjectOutput out) 75 | throws IOException 76 | { 77 | TreeSetMap treeMap = (TreeSetMap)map; 78 | out.writeObject(treeMap.getComparator()); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/serialization/TreeSetProxy.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.serialization; 37 | 38 | import org.javimmutable.collections.ISet; 39 | import org.javimmutable.collections.tree.TreeSet; 40 | 41 | import java.io.IOException; 42 | import java.io.ObjectInput; 43 | import java.io.ObjectOutput; 44 | import java.util.Comparator; 45 | 46 | @SuppressWarnings("unchecked") 47 | public class TreeSetProxy 48 | extends AbstractSetProxy 49 | { 50 | private static final long serialVersionUID = -121805; 51 | 52 | public TreeSetProxy() 53 | { 54 | super(TreeSet.of()); 55 | } 56 | 57 | public TreeSetProxy(TreeSet set) 58 | { 59 | super(set); 60 | } 61 | 62 | @Override 63 | protected ISet readSet(ObjectInput in) 64 | throws IOException, ClassNotFoundException 65 | { 66 | Comparator comparator = (Comparator)in.readObject(); 67 | return TreeSet.of(comparator); 68 | } 69 | 70 | @Override 71 | protected void writeSet(ObjectOutput out) 72 | throws IOException 73 | { 74 | TreeSet treeSet = (TreeSet)set; 75 | out.writeObject(treeSet.getComparator()); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/setmap/HashSetMap.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.setmap; 37 | 38 | import org.javimmutable.collections.IMap; 39 | import org.javimmutable.collections.ISet; 40 | import org.javimmutable.collections.ISetMap; 41 | import org.javimmutable.collections.hash.HashMap; 42 | import org.javimmutable.collections.hash.HashSet; 43 | import org.javimmutable.collections.serialization.HashSetMapProxy; 44 | 45 | import javax.annotation.concurrent.Immutable; 46 | import java.io.Serializable; 47 | 48 | 49 | /** 50 | * {@link ISetMap} using a hash map for fast lookup. 51 | */ 52 | @Immutable 53 | public class HashSetMap 54 | extends AbstractSetMap 55 | implements Serializable 56 | { 57 | @SuppressWarnings("unchecked") 58 | private static final HashSetMap EMPTY = new HashSetMap(HashMap.of(), HashSet.of()); 59 | private static final long serialVersionUID = -121805; 60 | 61 | private HashSetMap(IMap> contents, 62 | ISet emptySet) 63 | { 64 | super(contents, emptySet); 65 | } 66 | 67 | @SuppressWarnings("unchecked") 68 | public static HashSetMap of() 69 | { 70 | return EMPTY; 71 | } 72 | 73 | @Override 74 | public void checkInvariants() 75 | { 76 | checkSetMapInvariants(); 77 | } 78 | 79 | @Override 80 | protected ISetMap create(IMap> map) 81 | { 82 | return new HashSetMap<>(map, emptySet); 83 | } 84 | 85 | private Object writeReplace() 86 | { 87 | return new HashSetMapProxy(this); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/org/javimmutable/collections/setmap/SetMapFactory.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.setmap; 37 | 38 | import org.javimmutable.collections.IMap; 39 | import org.javimmutable.collections.IMapEntry; 40 | import org.javimmutable.collections.ISet; 41 | import org.javimmutable.collections.ISetMap; 42 | import org.javimmutable.collections.hash.HashMap; 43 | import org.javimmutable.collections.hash.HashSet; 44 | 45 | import javax.annotation.Nonnull; 46 | import java.util.stream.Collector; 47 | 48 | public class SetMapFactory 49 | { 50 | private IMap> map = HashMap.of(); 51 | private ISet set = HashSet.of(); 52 | 53 | public ISetMap create() 54 | { 55 | return TemplateSetMap.of(map, set); 56 | } 57 | 58 | public Collector, ?, ISetMap> collector() 59 | { 60 | return create().setMapCollector(); 61 | } 62 | 63 | public SetMapFactory withMap(@Nonnull IMap> map) 64 | { 65 | this.map = map.deleteAll(); 66 | return this; 67 | } 68 | 69 | public SetMapFactory withSet(@Nonnull ISet set) 70 | { 71 | this.set = set.deleteAll(); 72 | return this; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/resources/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Burton Computer Corporation 2 | http://www.burton-computer.com 3 | 4 | Copyright (c) 2013, Burton Computer Corporation 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are 9 | met: 10 | 11 | Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the 17 | distribution. 18 | 19 | Neither the name of the Burton Computer Corporation nor the names 20 | of its contributors may be used to endorse or promote products 21 | derived from this software without specific prior written 22 | permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | -------------------------------------------------------------------------------- /src/test/java/org/javimmutable/collections/SplitableIterableTest.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | import junit.framework.TestCase; 39 | 40 | import java.io.IOException; 41 | 42 | public class SplitableIterableTest 43 | extends TestCase 44 | { 45 | public void testIndexedForEach() 46 | { 47 | IListBuilder collected = ILists.builder(); 48 | ILists.of(1, 2, 3).indexedForEach((i, v) -> collected.add(i).add(v)); 49 | assertEquals(ILists.of(0, 1, 1, 2, 2, 3), collected.build()); 50 | } 51 | 52 | public void testIndexedForEachThrows() 53 | { 54 | IListBuilder collected = ILists.builder(); 55 | try { 56 | ILists.of(1, 2, 3).indexedForEachThrows((i, v) -> { 57 | if (i == 2) { 58 | throw new IOException(); 59 | } 60 | collected.add(i).add(v); 61 | }); 62 | fail(); 63 | } catch (IOException ex) { 64 | assertEquals(ILists.of(0, 1, 1, 2), collected.build()); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/test/java/org/javimmutable/collections/Tuple2Test.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | import junit.framework.TestCase; 39 | 40 | public class Tuple2Test 41 | extends TestCase 42 | { 43 | public void test() 44 | { 45 | Tuple2 a10 = new Tuple2<>(10, "a"); 46 | Tuple2 a12 = new Tuple2<>(12, "a"); 47 | Tuple2 b10 = new Tuple2<>(12, "b"); 48 | assertEquals(true, a10.equals(a10)); 49 | assertEquals(true, a10.equals(Tuple2.of(10, "a"))); 50 | assertEquals(false, a10.equals(a12)); 51 | assertEquals(false, a10.equals(b10)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/org/javimmutable/collections/Tuple3Test.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | import junit.framework.TestCase; 39 | 40 | public class Tuple3Test 41 | extends TestCase 42 | { 43 | public void test() 44 | { 45 | Tuple3 a10b = new Tuple3<>("a", 10, "b"); 46 | Tuple3 a12b = new Tuple3<>("a", 12, "b"); 47 | Tuple3 a10c = new Tuple3<>("a", 10, "c"); 48 | Tuple3 b10b = new Tuple3<>("b", 10, "b"); 49 | assertEquals(true, a10b.equals(a10b)); 50 | assertEquals(true, a10b.equals(Tuple3.of("a", 10, "b"))); 51 | assertEquals(false, a10b.equals(a12b)); 52 | assertEquals(false, a10b.equals(a10c)); 53 | assertEquals(false, a10b.equals(b10b)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/org/javimmutable/collections/Tuple4Test.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections; 37 | 38 | import junit.framework.TestCase; 39 | 40 | public class Tuple4Test 41 | extends TestCase 42 | { 43 | public void test() 44 | { 45 | Tuple4 a10b900 = new Tuple4<>("a", 10, "b", 900); 46 | Tuple4 a12b900 = new Tuple4<>("a", 12, "b", 900); 47 | Tuple4 a10c900 = new Tuple4<>("a", 10, "c", 900); 48 | Tuple4 b10b900 = new Tuple4<>("b", 10, "b", 900); 49 | Tuple4 a10b1200 = new Tuple4<>("a", 10, "b", 1200); 50 | assertEquals(true, a10b900.equals(a10b900)); 51 | assertEquals(true, a10b900.equals(Tuple4.of("a", 10, "b", 900))); 52 | assertEquals(false, a10b900.equals(a12b900)); 53 | assertEquals(false, a10b900.equals(a10c900)); 54 | assertEquals(false, a10b900.equals(b10b900)); 55 | assertEquals(false, a10b900.equals(a10b1200)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/org/javimmutable/collections/common/Checked.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.common; 37 | 38 | import javax.annotation.concurrent.Immutable; 39 | 40 | @Immutable 41 | public class Checked 42 | { 43 | final int hashCode; 44 | final int value; 45 | 46 | public Checked(int hashCode, 47 | int value) 48 | { 49 | this.hashCode = hashCode; 50 | this.value = value; 51 | } 52 | 53 | @Override 54 | public boolean equals(Object o) 55 | { 56 | if (this == o) { 57 | return true; 58 | } 59 | if (o == null || getClass() != o.getClass()) { 60 | return false; 61 | } 62 | Checked checked = (Checked)o; 63 | return hashCode == checked.hashCode && 64 | value == checked.value; 65 | } 66 | 67 | @Override 68 | public int hashCode() 69 | { 70 | return hashCode; 71 | } 72 | 73 | public int value() 74 | { 75 | return value; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/test/java/org/javimmutable/collections/indexed/IndexedArrayTest.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.indexed; 37 | 38 | import junit.framework.TestCase; 39 | import org.javimmutable.collections.Indexed; 40 | 41 | import java.util.Arrays; 42 | 43 | public class IndexedArrayTest 44 | extends TestCase 45 | { 46 | public static Indexed makeIndexed(Integer... values) 47 | { 48 | return IndexedList.retained(Arrays.asList(values)); 49 | } 50 | 51 | public void test() 52 | { 53 | verifyEquals(IndexedArray.retained(new Integer[]{7, 8, 9}), makeIndexed(7, 8, 9)); 54 | verifyEquals(IndexedArray.copied(new Integer[]{7, 8, 9}), makeIndexed(7, 8, 9)); 55 | } 56 | 57 | private void verifyEquals(Indexed expected, 58 | Indexed actual) 59 | { 60 | assertEquals(expected.size(), actual.size()); 61 | for (int i = 0; i < expected.size(); ++i) { 62 | assertEquals(expected.get(i), actual.get(i)); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/org/javimmutable/collections/iterators/TransformIteratorTest.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.iterators; 37 | 38 | import junit.framework.TestCase; 39 | import org.javimmutable.collections.Indexed; 40 | import org.javimmutable.collections.indexed.IndexedHelper; 41 | 42 | import javax.annotation.Nonnull; 43 | 44 | import static java.util.Arrays.asList; 45 | import static org.javimmutable.collections.iterators.StandardIteratorTests.*; 46 | 47 | public class TransformIteratorTest 48 | extends TestCase 49 | { 50 | public void test() 51 | { 52 | verifyOrderedIterable(asList(), () -> iterator(IndexedHelper.empty())); 53 | verifyOrderedIterable(asList(1), () -> iterator(IndexedHelper.indexed(0))); 54 | verifyOrderedIterable(asList(1, 2), () -> iterator(IndexedHelper.indexed(0, 1))); 55 | verifyOrderedSplit(false, asList(), asList(), iterator(IndexedHelper.empty())); 56 | verifyOrderedSplit(false, asList(), asList(), iterator(IndexedHelper.indexed(0))); 57 | verifyOrderedSplit(true, asList(1), asList(2), iterator(IndexedHelper.indexed(0, 1))); 58 | verifyOrderedSplit(true, asList(1), asList(2, 3), iterator(IndexedHelper.indexed(0, 1, 2))); 59 | verifyOrderedSplit(true, asList(1, 2), asList(3, 4, 5), iterator(IndexedHelper.range(0, 4))); 60 | } 61 | 62 | private TransformIterator iterator(@Nonnull Indexed source) 63 | { 64 | return TransformIterator.of(IndexedIterator.iterator(source), x -> x + 1); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/org/javimmutable/collections/list/IteratorTest.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.list; 37 | 38 | import junit.framework.TestCase; 39 | import org.javimmutable.collections.SplitIterator; 40 | import org.javimmutable.collections.SplitableIterator; 41 | 42 | import java.util.ArrayList; 43 | import java.util.List; 44 | 45 | import static org.javimmutable.collections.iterators.StandardIteratorTests.verifyOrderedIterable; 46 | 47 | public class IteratorTest 48 | extends TestCase 49 | { 50 | public void testVarious() 51 | { 52 | List list = new ArrayList<>(); 53 | TreeBuilder tree = new TreeBuilder<>(); 54 | for (int i = 1; i <= 1024; ++i) { 55 | verifyOrderedIterable(list, tree.build()); 56 | 57 | List traversed = new ArrayList<>(); 58 | traverse(traversed, tree.build().iterator()); 59 | assertEquals(traversed, list); 60 | 61 | list.add(i); 62 | tree.add(i); 63 | } 64 | } 65 | 66 | private void traverse(List values, 67 | SplitableIterator source) 68 | { 69 | if (source.isSplitAllowed()) { 70 | SplitIterator split = source.splitIterator(); 71 | traverse(values, split.getLeft()); 72 | traverse(values, split.getRight()); 73 | } else { 74 | while (source.hasNext()) { 75 | values.add(source.next()); 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/test/java/org/javimmutable/collections/list/TreeBuilderTest.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.list; 37 | 38 | import junit.framework.TestCase; 39 | 40 | import static org.assertj.core.api.Assertions.*; 41 | 42 | public class TreeBuilderTest 43 | extends TestCase 44 | { 45 | public void testBuilderRebuild() 46 | { 47 | for (int size = 0; size < 1024; ++size) { 48 | TreeBuilder builder = new TreeBuilder<>(); 49 | for (int i = 1; i <= size; ++i) { 50 | builder.add(i); 51 | } 52 | AbstractNode before = builder.build(); 53 | before.checkInvariants(); 54 | TreeBuilder second = new TreeBuilder<>(); 55 | second.rebuild(before); 56 | second.checkInvariants(); 57 | assertThat(second.size()).isEqualTo(before.size()); 58 | AbstractNode after = second.build(); 59 | after.checkInvariants(); 60 | assertEquals(TreeList.create(after), TreeList.create(before)); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/org/javimmutable/collections/stress_test/AbstractMapStressTestable.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.stress_test; 37 | 38 | import java.util.Map; 39 | 40 | abstract class AbstractMapStressTestable 41 | extends StressTester 42 | { 43 | AbstractMapStressTestable(String testName) 44 | { 45 | super(testName); 46 | } 47 | 48 | protected void verifyKeys(RandomKeyManager keys, 49 | Map expected) 50 | { 51 | if (keys.size() != expected.size()) { 52 | throw new RuntimeException(String.format("expected %d allocated found %d", expected.size(), keys.size())); 53 | } 54 | for (String value : expected.keySet()) { 55 | if (!keys.allocated(value)) { 56 | throw new RuntimeException(String.format("expected %s to be allocated but was not", value)); 57 | } 58 | } 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/org/javimmutable/collections/stress_test/ArrayIndexRange.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.stress_test; 37 | 38 | import java.util.Random; 39 | 40 | public abstract class ArrayIndexRange 41 | { 42 | public static final ArrayIndexRange BIT32 = new PositiveIndexRange(31); 43 | public static final ArrayIndexRange INTEGER = new AllIntIndexRange(); 44 | 45 | private ArrayIndexRange() 46 | { 47 | } 48 | 49 | public abstract int maxSize(); 50 | 51 | public abstract int randomIndex(Random random); 52 | 53 | private static class PositiveIndexRange 54 | extends ArrayIndexRange 55 | { 56 | private final int maxIndex; 57 | 58 | private PositiveIndexRange(int maxIndex) 59 | { 60 | this.maxIndex = maxIndex; 61 | } 62 | 63 | @Override 64 | public int maxSize() 65 | { 66 | return maxIndex + 1; 67 | } 68 | 69 | @Override 70 | public int randomIndex(Random random) 71 | { 72 | return random.nextInt(maxIndex + 1); 73 | } 74 | } 75 | 76 | private static class AllIntIndexRange 77 | extends ArrayIndexRange 78 | { 79 | private AllIntIndexRange() 80 | { 81 | } 82 | 83 | @Override 84 | public int maxSize() 85 | { 86 | return Integer.MAX_VALUE; 87 | } 88 | 89 | @Override 90 | public int randomIndex(Random random) 91 | { 92 | int base = random.nextInt(Integer.MAX_VALUE); 93 | return random.nextBoolean() ? base : -base; 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/test/java/org/javimmutable/collections/stress_test/IterationOrder.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.stress_test; 37 | 38 | public enum IterationOrder 39 | { 40 | UNORDERED, 41 | INSERT_ORDER, 42 | ORDERED 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/org/javimmutable/collections/tree/ComparableComparatorTest.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.tree; 37 | 38 | import junit.framework.TestCase; 39 | import org.javimmutable.collections.common.StandardSerializableTests; 40 | import org.javimmutable.collections.iterators.SingleValueIterator; 41 | 42 | public class ComparableComparatorTest 43 | extends TestCase 44 | { 45 | public void test() 46 | throws Exception 47 | { 48 | ComparableComparator comp = new ComparableComparator(); 49 | assertEquals(-1, comp.compare(null, "a")); 50 | assertEquals(0, comp.compare(null, null)); 51 | assertEquals(1, comp.compare("a", null)); 52 | assertEquals(-1, comp.compare("a", "b")); 53 | assertEquals(0, comp.compare("a", "a")); 54 | assertEquals(1, comp.compare("b", "a")); 55 | StandardSerializableTests.verifySerializable(c -> SingleValueIterator.of(c), null, comp, 56 | "H4sIAAAAAAAA/1vzloG1uIjBLL8oXS8rsSwzN7e0JDEpJ1UvOT8nJzW5JDM/r1ivpCg1Vc85P7cgsQgkB2WV5Bf9B4F/KsZMDAwVBQBVztHTSwAAAA=="); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/org/javimmutable/collections/tree/ValueNodeTest.java: -------------------------------------------------------------------------------- 1 | ///###//////////////////////////////////////////////////////////////////////// 2 | // 3 | // Burton Computer Corporation 4 | // http://www.burton-computer.com 5 | // 6 | // Copyright (c) 2024, Burton Computer Corporation 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are met: 11 | // 12 | // Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 15 | // Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in 17 | // the documentation and/or other materials provided with the 18 | // distribution. 19 | // 20 | // Neither the name of the Burton Computer Corporation nor the names 21 | // of its contributors may be used to endorse or promote products 22 | // derived from this software without specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | package org.javimmutable.collections.tree; 37 | 38 | import junit.framework.TestCase; 39 | 40 | import java.util.Comparator; 41 | 42 | public class ValueNodeTest 43 | extends TestCase 44 | { 45 | private final Comparator comparator = Comparator.naturalOrder(); 46 | 47 | public void testToString() 48 | { 49 | assertEquals("[]", FringeNode.instance().toString()); 50 | assertEquals("[(1,2)]", ValueNode.instance(1, 2).toString()); 51 | } 52 | 53 | public void testInstanceTypes() 54 | { 55 | AbstractNode node = ValueNode.instance(1, 10); 56 | assertTrue(node instanceof LeafNode); 57 | assertEquals("[(1,10)]", node.toString()); 58 | 59 | node = node.assign(comparator, 1, 20); 60 | assertTrue(node instanceof LeafNode); 61 | assertEquals("[(1,20)]", node.toString()); 62 | 63 | node = node.assign(comparator, 2, 90); 64 | assertTrue(node instanceof ValueNode); 65 | assertEquals("[(1,20),(2,90)]", node.toString()); 66 | 67 | assertSame(node, node.delete(comparator, 3)); 68 | 69 | node = node.delete(comparator, 1); 70 | assertTrue(node instanceof LeafNode); 71 | assertEquals("[(2,90)]", node.toString()); 72 | 73 | node = node.delete(comparator, 2); 74 | assertSame(FringeNode.instance(), node); 75 | assertEquals("[]", node.toString()); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/test/resources/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Burton Computer Corporation 2 | http://www.burton-computer.com 3 | 4 | Copyright (c) 2013, Burton Computer Corporation 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are 9 | met: 10 | 11 | Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the 17 | distribution. 18 | 19 | Neither the name of the Burton Computer Corporation nor the names 20 | of its contributors may be used to endorse or promote products 21 | derived from this software without specific prior written 22 | permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | --------------------------------------------------------------------------------