From a7adbb1e6da22432c460b56660c102927a534a6c Mon Sep 17 00:00:00 2001 From: Werner Randelshofer Date: Sun, 17 Dec 2023 11:35:57 +0100 Subject: [PATCH] Add static factory classes. --- org.jhotdraw8.application/pom.xml | 4 + .../AbstractFileBasedApplication.java | 35 +- .../application/FileBasedActivity.java | 2 +- .../AbstractSaveUnsavedChangesAction.java | 2 +- .../application/action/app/ExitAction.java | 2 +- .../action/file/AbstractOpenFileAction.java | 2 +- .../action/file/AbstractSaveFileAction.java | 2 +- .../action/file/OpenRecentFileAction.java | 2 +- .../action/file/RevertFileAction.java | 2 +- org.jhotdraw8.collection/pom.xml | 5 + .../org.jhotdraw8.collection/module-info.java | 6 +- .../jhotdraw8/collection/AddOnlyChampSet.java | 268 ------- .../org/jhotdraw8/collection/ChampMap.java | 341 --------- .../org/jhotdraw8/collection/ChampSet.java | 289 ------- .../org/jhotdraw8/collection/MapEntries.java | 406 ---------- .../jhotdraw8/collection/MutableChampMap.java | 351 --------- .../jhotdraw8/collection/MutableChampSet.java | 334 -------- .../jhotdraw8/collection/MutableMapEntry.java | 36 - .../collection/MutableVectorList.java | 317 -------- .../collection/MutableVectorMap.java | 496 ------------ .../collection/MutableVectorSet.java | 439 ----------- .../org/jhotdraw8/collection/VectorList.java | 382 ---------- .../org/jhotdraw8/collection/VectorMap.java | 474 ------------ .../org/jhotdraw8/collection/VectorSet.java | 466 ------------ .../collection/computed/ComputedList.java | 6 +- .../collection/facade/CollectionFacade.java | 93 --- .../collection/facade/ImmutableMapFacade.java | 161 ---- .../collection/facade/ImmutableSetFacade.java | 122 --- .../collection/facade/ListFacade.java | 139 ---- .../collection/facade/MapFacade.java | 125 --- .../collection/facade/MutableListFacade.java | 296 -------- .../collection/facade/MutableSetFacade.java | 116 --- .../facade/ReadOnlyCollectionFacade.java | 81 -- .../collection/facade/ReadOnlyListFacade.java | 79 -- .../collection/facade/ReadOnlyMapFacade.java | 87 --- .../facade/ReadOnlySequencedMapFacade.java | 76 -- .../facade/ReadOnlySequencedSetFacade.java | 73 -- .../collection/facade/ReadOnlySetFacade.java | 85 --- .../facade/ReadOnlySubListFacade.java | 224 ------ .../facade/SequencedCollectionFacade.java | 119 --- .../collection/facade/SequencedMapFacade.java | 210 ----- .../collection/facade/SequencedSetFacade.java | 148 ---- .../collection/facade/SetFacade.java | 123 --- .../collection/facade/package-info.java | 8 - .../immutable/ImmutableAddOnlySet.java | 27 - .../immutable/ImmutableCollection.java | 96 --- .../collection/immutable/ImmutableList.java | 186 ----- .../collection/immutable/ImmutableMap.java | 199 ----- .../ImmutableSequencedCollection.java | 108 --- .../immutable/ImmutableSequencedMap.java | 103 --- .../immutable/ImmutableSequencedSet.java | 81 -- .../collection/immutable/ImmutableSet.java | 147 ---- .../collection/immutable/ZipTransformer.java | 76 -- .../collection/immutable/package-info.java | 9 - .../collection/impl/IdentityObject.java | 20 - .../impl/champ/AbstractMutableChampMap.java | 201 ----- .../impl/champ/AbstractMutableChampSet.java | 196 ----- .../impl/champ/BitmapIndexedNode.java | 716 ------------------ .../impl/champ/BulkChangeEvent.java | 13 - .../collection/impl/champ/ChampIterator.java | 106 --- .../impl/champ/ChampSpliterator.java | 106 --- .../collection/impl/champ/ChangeEvent.java | 109 --- .../impl/champ/HashCollisionNode.java | 357 --------- .../impl/champ/MutableBitmapIndexedNode.java | 38 - .../impl/champ/MutableHashCollisionNode.java | 38 - .../jhotdraw8/collection/impl/champ/Node.java | 366 --------- .../collection/impl/champ/NodeFactory.java | 37 - .../ReverseTombSkippingVectorSpliterator.java | 47 -- .../collection/impl/champ/SequencedData.java | 151 ---- .../impl/champ/SequencedElement.java | 89 --- .../collection/impl/champ/SequencedEntry.java | 76 -- .../champ/TombSkippingVectorSpliterator.java | 50 -- .../impl/champ/VectorTombstone.java | 76 -- .../collection/impl/champ/package-info.java | 21 - .../collection/impl/vector/ArrayType.java | 657 ---------------- .../collection/impl/vector/BitMappedTrie.java | 578 -------------- .../collection/impl/vector/LeafVisitor.java | 24 - .../collection/impl/vector/NodeModifier.java | 27 - .../collection/mapped/MappedReadOnlyList.java | 8 +- .../collection/primitive/ByteArrayList.java | 17 +- .../primitive/ByteSequencedCollection.java | 3 +- .../collection/primitive/DoubleArrayList.java | 19 +- .../primitive/DoubleSequencedCollection.java | 3 +- .../collection/primitive/IntArrayDeque.java | 10 +- .../collection/primitive/IntArrayList.java | 19 +- .../collection/primitive/IntRangeSet.java | 2 +- .../primitive/IntSequencedCollection.java | 3 +- .../readonly/AbstractReadOnlyCollection.java | 53 -- .../readonly/AbstractReadOnlyList.java | 30 - .../readonly/AbstractReadOnlyMap.java | 35 - .../readonly/AbstractReadOnlySet.java | 28 - .../readonly/ReadOnlyCollection.java | 190 ----- .../collection/readonly/ReadOnlyList.java | 277 ------- .../collection/readonly/ReadOnlyMap.java | 314 -------- .../readonly/ReadOnlySequencedCollection.java | 51 -- .../readonly/ReadOnlySequencedMap.java | 149 ---- .../readonly/ReadOnlySequencedSet.java | 37 - .../collection/readonly/ReadOnlySet.java | 104 --- .../collection/readonly/package-info.java | 9 - .../sequenced/AbstractSequencedMap.java | 174 ----- .../sequenced/AbstractSequencedSet.java | 64 -- .../sequenced/SequencedCollection.java | 95 --- .../collection/sequenced/SequencedMap.java | 146 ---- .../collection/sequenced/SequencedSet.java | 27 - .../collection/sequenced/package-info.java | 11 - .../spliterator/ReadOnlyListSpliterator.java | 2 +- .../collection/AbstractImmutableListTest.java | 4 - .../collection/AbstractImmutableMapTest.java | 553 -------------- .../AbstractImmutableSequencedMapTest.java | 226 ------ .../AbstractImmutableSequencedSetTest.java | 88 --- .../collection/AbstractImmutableSetTest.java | 645 ---------------- .../AbstractIntSequencedCollectionTest.java | 89 --- .../AbstractListLongRunningTest.java | 39 - .../collection/AbstractListTest.java | 118 --- .../jhotdraw8/collection/AbstractMapTest.java | 649 ---------------- .../collection/AbstractReadOnlyListTest.java | 28 - .../collection/AbstractReadOnlyMapTest.java | 22 - .../collection/AbstractReadOnlySetTest.java | 28 - .../AbstractSequencedCollectionTest.java | 84 -- .../collection/AbstractSequencedMapTest.java | 251 ------ .../collection/AbstractSequencedSetTest.java | 451 ----------- .../AbstractSetLongRunningTest.java | 38 - .../jhotdraw8/collection/AbstractSetTest.java | 714 ----------------- .../collection/AddOnlyChampSetTest.java | 95 --- .../jhotdraw8/collection/ChampMapTest.java | 40 - .../jhotdraw8/collection/ChampSetTest.java | 66 -- .../jhotdraw8/collection/HashCollider.java | 64 -- .../org/jhotdraw8/collection/HashSetTest.java | 44 -- .../org/jhotdraw8/collection/MapData.java | 124 --- .../jhotdraw8/collection/MapFacadeTest.java | 38 - .../collection/MutableChampMapTest.java | 59 -- .../MutableChampSetLongRunningTest.java | 19 - .../collection/MutableChampSetTest.java | 38 - .../MutableVectorListLongRunningTest.java | 19 - .../collection/MutableVectorListTest.java | 18 - .../collection/MutableVectorMapTest.java | 53 -- .../collection/MutableVectorSetTest.java | 86 --- .../jhotdraw8/collection/OrderedPairTest.java | 29 - .../org/jhotdraw8/collection/SetData.java | 123 --- .../jhotdraw8/collection/VectorListTest.java | 19 - .../jhotdraw8/collection/VectorMapTest.java | 40 - .../jhotdraw8/collection/VectorSetTest.java | 42 - .../collection/computed/ComputedListTest.java | 40 - .../facade/ImmutableMapFacadeTest.java | 46 -- .../facade/ImmutableSetFacadeTest.java | 62 -- .../collection/guava/ChampSetGuavaTests.java | 65 -- .../guava/MutableChampMapGuavaTests.java | 65 -- .../guava/MutableChampSetGuavaTests.java | 63 -- .../guava/MutableVectorListGuavaTests.java | 63 -- .../guava/MutableVectorMapGuavaTests.java | 67 -- .../guava/MutableVectorSetGuavaTests.java | 86 --- .../guava/VectorListGuavaTests.java | 65 -- .../collection/immutable/ZipperTest.java | 35 - .../jhotdraw8/collection/jmh/ChampMapJmh.java | 216 ------ .../jhotdraw8/collection/jmh/ChampSetJmh.java | 250 ------ .../collection/jmh/MutableVectorListJmh.java | 204 ----- .../collection/jmh/VectorListJmh.java | 204 ----- .../collection/jmh/VectorMapJmh.java | 214 ------ .../collection/jmh/VectorSetJmh.java | 184 ----- .../jhotdraw8/collection/jol/ChampMapJol.java | 94 --- .../jhotdraw8/collection/jol/ChampSetJol.java | 107 --- .../collection/jol/VectorMapJol.java | 105 --- .../primitive/IntArrayDequeTest.java | 19 - .../primitive/IntArrayListTest.java | 19 - .../collection/primitive/IntSetTest.java | 122 --- .../primitive/LongArrayDequeTest.java | 83 -- .../primitive/LongArrayHeapTest.java | 42 - org.jhotdraw8.css/pom.xml | 8 + .../java/org.jhotdraw8.css/module-info.java | 1 + .../org/jhotdraw8/css/ast/AtRule.java | 6 +- .../org/jhotdraw8/css/ast/Declaration.java | 4 +- .../org/jhotdraw8/css/ast/SelectorGroup.java | 4 +- .../org/jhotdraw8/css/ast/StyleRule.java | 4 +- .../org/jhotdraw8/css/ast/Stylesheet.java | 6 +- .../jhotdraw8/css/converter/CssConverter.java | 4 +- .../css/converter/CssListConverter.java | 4 +- .../css/converter/CssMappedConverter.java | 2 +- .../css/converter/CssSetConverter.java | 8 +- .../css/function/VarCssFunction.java | 2 +- .../css/manager/CssFunctionProcessor.java | 6 +- .../manager/SimpleCssFunctionProcessor.java | 6 +- .../css/manager/SimpleStylesheetsManager.java | 26 +- .../css/model/DocumentSelectorModel.java | 6 +- .../jhotdraw8/css/model/SelectorModel.java | 4 +- .../css/model/StyleableSelectorModel.java | 6 +- .../css/parser/ListCssTokenizer.java | 6 +- .../css/AbstractCssFunctionProcessorTest.java | 4 +- .../org/jhotdraw8/css/CssParserTest.java | 2 +- .../css/ExtendedCssFunctionProcessorTest.java | 2 +- .../css/SimpleCssFunctionProcessorTest.java | 2 +- .../java/org.jhotdraw8.draw/module-info.java | 1 + .../draw/action/SelectSameAction.java | 2 +- .../converter/CssBezierNodeListConverter.java | 2 +- .../css/converter/CssEffectConverter.java | 4 +- .../converter/CssFXPathElementsConverter.java | 4 +- .../converter/CssStrokeStyleConverter.java | 4 +- .../draw/css/model/FigureSelectorModel.java | 4 +- .../draw/css/value/CssStrokeStyle.java | 4 +- .../draw/css/value/NamedCssColor.java | 4 +- .../draw/css/value/SystemCssColor.java | 4 +- .../draw/figure/AbstractDrawing.java | 2 +- .../jhotdraw8/draw/figure/AbstractFigure.java | 6 +- .../figure/AbstractLabelConnectionFigure.java | 4 +- .../draw/figure/AbstractLabelFigure.java | 2 +- .../figure/AbstractLineConnectionFigure.java | 6 +- .../jhotdraw8/draw/figure/BezierFigure.java | 4 +- .../draw/figure/CombinedPathFigure.java | 2 +- .../org/jhotdraw8/draw/figure/Drawing.java | 2 +- .../org/jhotdraw8/draw/figure/Figure.java | 4 +- .../draw/figure/MarkerStrokableFigure.java | 4 +- .../org/jhotdraw8/draw/figure/PageFigure.java | 4 +- .../jhotdraw8/draw/figure/PolygonFigure.java | 4 +- .../jhotdraw8/draw/figure/PolylineFigure.java | 4 +- .../draw/figure/SecondStrokableFigure.java | 4 +- .../draw/figure/StrokableFigure.java | 4 +- .../draw/figure/StyleableFigure.java | 4 +- .../draw/figure/TextStrokeableFigure.java | 4 +- .../draw/figure/TransformableFigure.java | 4 +- .../handle/BezierControlPointEditHandle.java | 4 +- .../draw/handle/BezierNodeEditHandle.java | 4 +- .../draw/handle/BezierNodeMoveHandle.java | 2 +- .../draw/handle/BezierNodeTangentHandle.java | 2 +- .../draw/handle/BezierPathEditHandle.java | 4 +- .../draw/handle/BezierPathOutlineHandle.java | 2 +- .../draw/handle/PolyPointEditHandle.java | 2 +- .../draw/handle/PolyPointMoveHandle.java | 2 +- .../draw/handle/PolygonOutlineHandle.java | 2 +- .../draw/handle/PolylineOutlineHandle.java | 2 +- .../draw/handle/TransformHandleKit.java | 4 +- .../draw/inspector/HierarchyInspector.java | 4 +- .../draw/inspector/StyleClassesInspector.java | 4 +- .../draw/inspector/StylesheetsInspector.java | 4 +- .../draw/io/AbstractExportOutputFormat.java | 4 +- .../draw/io/AbstractInputFormat.java | 4 +- .../draw/io/DefaultFigureFactory.java | 2 +- .../jhotdraw8/draw/io/ExportOutputFormat.java | 2 +- .../org/jhotdraw8/draw/io/FigureFactory.java | 2 +- .../org/jhotdraw8/draw/io/InputFormat.java | 2 +- .../org/jhotdraw8/draw/io/OutputFormat.java | 2 +- .../draw/io/SimpleXmlStaxReader.java | 4 +- .../jhotdraw8/draw/io/SimpleXmlWriter.java | 20 +- .../draw/io/XmlEncoderOutputFormat.java | 4 +- .../draw/key/BezierNodeListStyleableKey.java | 4 +- .../draw/key/BoundingBoxMapAccessor.java | 2 +- .../key/BoundingBoxStyleableMapAccessor.java | 2 +- .../key/CssInsetsStyleableMapAccessor.java | 2 +- .../key/CssPoint2DStyleableMapAccessor.java | 2 +- .../CssRectangle2DStyleableMapAccessor.java | 2 +- .../draw/key/DoubleListStyleableKey.java | 2 +- .../draw/key/EffectStyleableKey.java | 2 +- .../draw/key/FontStyleableMapAccessor.java | 2 +- .../draw/key/InsetsStyleableMapAccessor.java | 2 +- .../jhotdraw8/draw/key/ListStyleableKey.java | 4 +- .../NullableBezierNodeListStyleableKey.java | 2 +- ...bleCssRectangle2DStyleableMapAccessor.java | 2 +- .../NullableFXPathElementsStyleableKey.java | 2 +- .../draw/key/NullableListStyleableKey.java | 4 +- .../draw/key/NullableSetStyleableKey.java | 4 +- .../key/PaperSizeStyleableMapAccessor.java | 2 +- .../draw/key/Point2DListStyleableKey.java | 4 +- .../draw/key/Point2DStyleableMapAccessor.java | 2 +- .../draw/key/Point3DStyleableMapAccessor.java | 2 +- .../draw/key/Rectangle2DMapAccessor.java | 2 +- .../key/Rectangle2DStyleableMapAccessor.java | 2 +- .../draw/key/Scale2DStyleableMapAccessor.java | 2 +- .../draw/key/Scale3DStyleableMapAccessor.java | 2 +- .../jhotdraw8/draw/key/SetStyleableKey.java | 4 +- .../draw/key/StrokeStyleableMapAccessor.java | 4 +- ...mmetricCssPoint2DStyleableMapAccessor.java | 2 +- .../draw/key/TransformListStyleableKey.java | 4 +- .../org/jhotdraw8/draw/key/WordSetKey.java | 2 +- .../draw/key/WordSetStyleableKey.java | 4 +- .../jhotdraw8/draw/popup/ExamplesPicker.java | 2 +- .../draw/tool/BezierCreationTool.java | 4 +- .../jhotdraw8/draw/tool/PolyCreationTool.java | 2 +- .../converter/XmlBezierNodeListConverter.java | 4 +- .../xml/converter/XmlFXSvgPathConverter.java | 4 +- .../draw/AbstractCompositeFigureTest.java | 2 +- .../css/converter/CssListConverterTest.java | 4 +- .../css/converter/CssStrokeConverterTest.java | 2 +- .../css/model/FigureSelectorModelTest.java | 2 +- .../AbstractCssFunctionProcessorTest.java | 4 +- .../value/function/LadderCssFunctionTest.java | 2 +- .../org/jhotdraw8/draw/figure/FigureTest.java | 4 +- .../AbstractStyleablePropertyBeanTest.java | 2 +- .../jhotdraw8/examples/mini/CssExample.java | 2 +- .../fxbase/styleable/StyleableBean.java | 2 +- .../WritableStyleableMapAccessor.java | 4 +- org.jhotdraw8.fxcollection/pom.xml | 5 + .../module-info.java | 1 + .../fxcollection/AbstractObservableSet.java | 2 +- .../facade/ObservableListFacade.java | 4 +- .../facade/ObservableSetFacade.java | 4 +- .../AbstractIndexedArrayObservableSet.java | 23 +- .../fxcollection/typesafekey/Key.java | 4 +- .../fxcollection/typesafekey/MapAccessor.java | 4 +- .../fxcollection/typesafekey/NonNullKey.java | 2 +- .../typesafekey/NonNullMapAccessor.java | 2 +- .../fxcollection/typesafekey/NullableKey.java | 2 +- .../typesafekey/SetValueMapAccessor.java | 6 +- .../typesafekey/SimpleNonNullListKey.java | 4 +- org.jhotdraw8.fxcontrols/pom.xml | 4 + .../org.jhotdraw8.fxcontrols/module-info.java | 1 + .../fxcontrols/dock/AbstractDockable.java | 4 +- .../jhotdraw8/fxcontrols/dock/DockNode.java | 2 +- .../jhotdraw8/fxcontrols/dock/DockParent.java | 4 +- .../fxcontrols/dock/SimpleDockable.java | 4 +- org.jhotdraw8.geom/pom.xml | 4 + .../java/org.jhotdraw8.geom/module-info.java | 1 + .../jhotdraw8/geom/CutStartPathBuilder.java | 2 +- .../geom/contour/ContourBuilder.java | 37 +- .../geom/contour/ContourIntersections.java | 17 +- .../geom/intersect/IntersectionResult.java | 6 +- .../geom/intersect/IntersectionResultEx.java | 4 +- .../jhotdraw8/geom/shape/BezierNodePath.java | 2 +- .../geom/shape/BezierNodePathBuilder.java | 4 +- org.jhotdraw8.graph/pom.xml | 4 + .../java/org.jhotdraw8.graph/module-info.java | 1 + .../org/jhotdraw8/graph/BidiGraph.java | 2 +- .../org/jhotdraw8/graph/DirectedGraph.java | 2 +- .../graph/SimpleMutableDirectedGraph.java | 2 +- .../graph/path/AllArcSequencesFinder.java | 2 +- .../graph/path/AllArrowsSequencesFinder.java | 2 +- .../graph/path/AllVertexSequencesFinder.java | 2 +- .../graph/path/ArcSequenceFinder.java | 4 +- .../graph/path/ArrowSequenceFinder.java | 4 +- .../SimpleCombinedAllSequencesFinder.java | 2 +- .../path/SimpleCombinedSequenceFinder.java | 2 +- .../SimpleIndexedVertexSequenceFinder.java | 2 +- .../path/SimpleVertexSequenceFinder.java | 2 +- .../graph/path/VertexSequenceFinder.java | 4 +- .../graph/path/algo/AllWalksSpliterator.java | 2 +- .../algo/UniqueOnDigArcPathSearchAlgo.java | 8 +- .../algo/UniqueOnDigVertexPathSearchAlgo.java | 2 +- .../backlink/ArcBackLinkWithAncestorSet.java | 2 +- .../path/backlink/ArcBackLinkWithCost.java | 4 +- .../IndexedVertexBackLinkWithCost.java | 4 +- .../VertexBackLinkWithAncestorSet.java | 2 +- .../path/backlink/VertexBackLinkWithCost.java | 4 +- .../graph/BfsDfsArcSpliteratorTest.java | 10 +- ...niqueOrOneHopVertexPathSearchAlgoTest.java | 8 +- .../path/algo/AllWalksSpliteratorTest.java | 4 +- .../algo/ArbitraryArcPathSearchAlgoTest.java | 4 +- ...rbitraryShortestArcPathSearchAlgoTest.java | 8 +- .../UniqueOnDagVertexPathSearchAlgoTest.java | 6 +- .../UniqueShortestArcPathSearchAlgoTest.java | 4 +- .../jhotdraw8/grapher/GrapherActivity.java | 4 +- .../module-info.java | 2 + .../jhotdraw8/icollection/ImmutableLists.java | 50 ++ .../jhotdraw8/icollection/ImmutableMaps.java | 56 ++ .../icollection/ImmutableSequencedMaps.java | 59 ++ .../icollection/ImmutableSequencedSets.java | 54 ++ .../jhotdraw8/icollection/ImmutableSets.java | 52 ++ .../jhotdraw8/icollection/ReadOnlyLists.java | 79 ++ .../jhotdraw8/icollection/ReadOnlyMaps.java | 83 ++ .../icollection/ReadOnlySequencedMaps.java | 85 +++ .../icollection/ReadOnlySequencedSets.java | 78 ++ .../jhotdraw8/icollection/ReadOnlySets.java | 76 ++ .../SizeLimitExceededException.java | 3 +- .../ReadOnlySequencedCollectionFacade.java | 11 +- org.jhotdraw8.os/pom.xml | 4 + .../java/org.jhotdraw8.os/module-info.java | 1 + .../os/macos/MacOSPreferencesTest.java | 2 +- org.jhotdraw8.svg/pom.xml | 4 + .../java/org.jhotdraw8.svg/module-info.java | 1 + .../svg/figure/AbstractSvgGradientFigure.java | 4 +- .../svg/figure/SvgDefaultableFigure.java | 12 +- .../svg/figure/SvgLinearGradientFigure.java | 2 +- .../svg/figure/SvgPolygonFigure.java | 4 +- .../svg/figure/SvgPolylineFigure.java | 4 +- .../svg/figure/SvgRadialGradientFigure.java | 2 +- .../svg/figure/SvgTransformableFigure.java | 4 +- .../jhotdraw8/svg/io/AbstractFXSvgWriter.java | 47 +- .../jhotdraw8/svg/io/FigureSvgTinyReader.java | 6 +- .../svg/io/SvgFontFamilyConverter.java | 4 +- .../svg/text/SvgFontSizeConverter.java | 6 +- .../org/jhotdraw8/teddy/TeddyActivity.java | 2 +- org.jhotdraw8.xml/pom.xml | 4 + .../java/org.jhotdraw8.xml/module-info.java | 1 + .../xml/converter/XmlWordListConverter.java | 4 +- .../xml/converter/XmlWordSetConverter.java | 6 +- pom.xml | 5 + 382 files changed, 1294 insertions(+), 21839 deletions(-) delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AddOnlyChampSet.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/ChampMap.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/ChampSet.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MapEntries.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableChampMap.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableChampSet.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableMapEntry.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorList.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorMap.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorSet.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorList.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorMap.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorSet.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/CollectionFacade.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ImmutableMapFacade.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ImmutableSetFacade.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ListFacade.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/MapFacade.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/MutableListFacade.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/MutableSetFacade.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlyCollectionFacade.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlyListFacade.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlyMapFacade.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlySequencedMapFacade.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlySequencedSetFacade.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlySetFacade.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlySubListFacade.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/SequencedCollectionFacade.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/SequencedMapFacade.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/SequencedSetFacade.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/SetFacade.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/package-info.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableAddOnlySet.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableCollection.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableList.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableMap.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableSequencedCollection.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableSequencedMap.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableSequencedSet.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableSet.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ZipTransformer.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/package-info.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/IdentityObject.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/AbstractMutableChampMap.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/AbstractMutableChampSet.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/BitmapIndexedNode.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/BulkChangeEvent.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/ChampIterator.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/ChampSpliterator.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/ChangeEvent.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/HashCollisionNode.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/MutableBitmapIndexedNode.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/MutableHashCollisionNode.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/Node.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/NodeFactory.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/ReverseTombSkippingVectorSpliterator.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/SequencedData.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/SequencedElement.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/SequencedEntry.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/TombSkippingVectorSpliterator.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/VectorTombstone.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/package-info.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/vector/ArrayType.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/vector/BitMappedTrie.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/vector/LeafVisitor.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/vector/NodeModifier.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/AbstractReadOnlyCollection.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/AbstractReadOnlyList.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/AbstractReadOnlyMap.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/AbstractReadOnlySet.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlyCollection.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlyList.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlyMap.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlySequencedCollection.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlySequencedMap.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlySequencedSet.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlySet.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/package-info.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/AbstractSequencedMap.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/AbstractSequencedSet.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/SequencedCollection.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/SequencedMap.java delete mode 100644 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/SequencedSet.java delete mode 100755 org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/package-info.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractImmutableListTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractImmutableMapTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractImmutableSequencedMapTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractImmutableSequencedSetTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractImmutableSetTest.java delete mode 100755 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractIntSequencedCollectionTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractListLongRunningTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractListTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractMapTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractReadOnlyListTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractReadOnlyMapTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractReadOnlySetTest.java delete mode 100755 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractSequencedCollectionTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractSequencedMapTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractSequencedSetTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractSetLongRunningTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractSetTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AddOnlyChampSetTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/ChampMapTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/ChampSetTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/HashCollider.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/HashSetTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MapData.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MapFacadeTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableChampMapTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableChampSetLongRunningTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableChampSetTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorListLongRunningTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorListTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorMapTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorSetTest.java delete mode 100755 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/OrderedPairTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/SetData.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorListTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorMapTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorSetTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/computed/ComputedListTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ImmutableMapFacadeTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ImmutableSetFacadeTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/ChampSetGuavaTests.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/MutableChampMapGuavaTests.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/MutableChampSetGuavaTests.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/MutableVectorListGuavaTests.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/MutableVectorMapGuavaTests.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/MutableVectorSetGuavaTests.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/VectorListGuavaTests.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ZipperTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/ChampMapJmh.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/ChampSetJmh.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/MutableVectorListJmh.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/VectorListJmh.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/VectorMapJmh.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/VectorSetJmh.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jol/ChampMapJol.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jol/ChampSetJol.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jol/VectorMapJol.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntArrayDequeTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntArrayListTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntSetTest.java delete mode 100755 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/LongArrayDequeTest.java delete mode 100644 org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/LongArrayHeapTest.java create mode 100644 org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ImmutableLists.java create mode 100644 org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ImmutableMaps.java create mode 100644 org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ImmutableSequencedMaps.java create mode 100644 org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ImmutableSequencedSets.java create mode 100644 org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ImmutableSets.java create mode 100644 org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ReadOnlyLists.java create mode 100644 org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ReadOnlyMaps.java create mode 100644 org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ReadOnlySequencedMaps.java create mode 100644 org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ReadOnlySequencedSets.java create mode 100644 org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ReadOnlySets.java rename {org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly => org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/exception}/SizeLimitExceededException.java (95%) rename {org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection => org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection}/facade/ReadOnlySequencedCollectionFacade.java (88%) mode change 100755 => 100644 diff --git a/org.jhotdraw8.application/pom.xml b/org.jhotdraw8.application/pom.xml index 5f7c1290d..f3b98d56d 100644 --- a/org.jhotdraw8.application/pom.xml +++ b/org.jhotdraw8.application/pom.xml @@ -83,6 +83,10 @@ org.jhotdraw8.fxbase + ch.randelshofer + org.jhotdraw8.icollection + + org.junit.jupiter junit-jupiter test diff --git a/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/AbstractFileBasedApplication.java b/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/AbstractFileBasedApplication.java index 92c951fb8..6a5079c15 100755 --- a/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/AbstractFileBasedApplication.java +++ b/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/AbstractFileBasedApplication.java @@ -17,7 +17,12 @@ import javafx.geometry.Rectangle2D; import javafx.scene.Node; import javafx.scene.Scene; -import javafx.scene.control.*; +import javafx.scene.control.Alert; +import javafx.scene.control.CheckMenuItem; +import javafx.scene.control.Menu; +import javafx.scene.control.MenuBar; +import javafx.scene.control.MenuItem; +import javafx.scene.control.SeparatorMenuItem; import javafx.scene.image.ImageView; import javafx.scene.input.DataFormat; import javafx.scene.input.KeyCombination; @@ -34,12 +39,20 @@ import org.jhotdraw8.application.action.ScreenMenuBarProxyAction; import org.jhotdraw8.application.action.app.AboutAction; import org.jhotdraw8.application.action.app.ExitAction; -import org.jhotdraw8.application.action.edit.*; -import org.jhotdraw8.application.action.file.*; +import org.jhotdraw8.application.action.edit.ClearSelectionAction; +import org.jhotdraw8.application.action.edit.CopyAction; +import org.jhotdraw8.application.action.edit.CutAction; +import org.jhotdraw8.application.action.edit.DeleteAction; +import org.jhotdraw8.application.action.edit.PasteAction; +import org.jhotdraw8.application.action.edit.SelectAllAction; +import org.jhotdraw8.application.action.file.ClearRecentFilesMenuAction; +import org.jhotdraw8.application.action.file.CloseFileAction; +import org.jhotdraw8.application.action.file.NewFileAction; +import org.jhotdraw8.application.action.file.OpenFileAction; +import org.jhotdraw8.application.action.file.OpenRecentFileAction; import org.jhotdraw8.application.prefs.PreferencesUtil; import org.jhotdraw8.application.resources.Resources; import org.jhotdraw8.base.text.NaturalSortCollator; -import org.jhotdraw8.collection.ChampMap; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.fxbase.binding.CustomBinding; import org.jhotdraw8.fxbase.concurrent.FXWorker; @@ -47,12 +60,24 @@ import org.jhotdraw8.fxbase.tree.PreorderSpliterator; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.SimpleNullableKey; +import org.jhotdraw8.icollection.ChampMap; import java.lang.ref.WeakReference; import java.net.URI; import java.net.URISyntaxException; import java.nio.file.Paths; -import java.util.*; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Deque; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.WeakHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.function.Supplier; diff --git a/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/FileBasedActivity.java b/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/FileBasedActivity.java index d216021c8..4a80301cd 100755 --- a/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/FileBasedActivity.java +++ b/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/FileBasedActivity.java @@ -12,7 +12,6 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.application.action.Action; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.fxbase.concurrent.CompletableWorker; import org.jhotdraw8.fxbase.concurrent.FXWorker; import org.jhotdraw8.fxbase.concurrent.SimpleCompletableWorker; @@ -20,6 +19,7 @@ import org.jhotdraw8.fxbase.concurrent.WorkState; import org.jhotdraw8.fxbase.control.Disableable; import org.jhotdraw8.fxcollection.typesafekey.Key; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.net.URI; import java.util.concurrent.CompletionStage; diff --git a/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/AbstractSaveUnsavedChangesAction.java b/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/AbstractSaveUnsavedChangesAction.java index 1a0776e0f..c16e76d1c 100755 --- a/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/AbstractSaveUnsavedChangesAction.java +++ b/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/AbstractSaveUnsavedChangesAction.java @@ -24,9 +24,9 @@ import org.jhotdraw8.application.controls.urichooser.URIChooser; import org.jhotdraw8.application.resources.Resources; import org.jhotdraw8.base.net.UriUtil; -import org.jhotdraw8.collection.ChampMap; import org.jhotdraw8.fxbase.concurrent.SimpleWorkState; import org.jhotdraw8.fxbase.concurrent.WorkState; +import org.jhotdraw8.icollection.ChampMap; import java.net.URI; import java.util.concurrent.CancellationException; diff --git a/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/app/ExitAction.java b/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/app/ExitAction.java index 7c006817c..5bf202e2b 100755 --- a/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/app/ExitAction.java +++ b/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/app/ExitAction.java @@ -22,9 +22,9 @@ import org.jhotdraw8.application.controls.urichooser.URIChooser; import org.jhotdraw8.application.resources.Resources; import org.jhotdraw8.base.net.UriUtil; -import org.jhotdraw8.collection.ChampMap; import org.jhotdraw8.fxbase.concurrent.SimpleWorkState; import org.jhotdraw8.fxbase.concurrent.WorkState; +import org.jhotdraw8.icollection.ChampMap; import java.net.URI; import java.util.ArrayList; diff --git a/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/file/AbstractOpenFileAction.java b/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/file/AbstractOpenFileAction.java index ad77d34fa..111f014e5 100755 --- a/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/file/AbstractOpenFileAction.java +++ b/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/file/AbstractOpenFileAction.java @@ -20,12 +20,12 @@ import org.jhotdraw8.application.controls.urichooser.URIChooser; import org.jhotdraw8.application.resources.Resources; import org.jhotdraw8.base.net.UriUtil; -import org.jhotdraw8.collection.ChampMap; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.fxbase.concurrent.SimpleWorkState; import org.jhotdraw8.fxbase.concurrent.WorkState; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.SimpleNullableKey; +import org.jhotdraw8.icollection.ChampMap; import java.net.URI; import java.util.Map; diff --git a/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/file/AbstractSaveFileAction.java b/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/file/AbstractSaveFileAction.java index 3b0d19ebe..d45147d50 100755 --- a/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/file/AbstractSaveFileAction.java +++ b/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/file/AbstractSaveFileAction.java @@ -21,12 +21,12 @@ import org.jhotdraw8.application.controls.urichooser.URIChooser; import org.jhotdraw8.application.resources.Resources; import org.jhotdraw8.base.net.UriUtil; -import org.jhotdraw8.collection.ChampMap; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.fxbase.concurrent.SimpleWorkState; import org.jhotdraw8.fxbase.concurrent.WorkState; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.SimpleNullableKey; +import org.jhotdraw8.icollection.ChampMap; import java.net.URI; import java.util.LinkedHashMap; diff --git a/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/file/OpenRecentFileAction.java b/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/file/OpenRecentFileAction.java index 9ce12d71c..05405f55e 100755 --- a/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/file/OpenRecentFileAction.java +++ b/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/file/OpenRecentFileAction.java @@ -17,9 +17,9 @@ import org.jhotdraw8.application.action.Action; import org.jhotdraw8.application.resources.Resources; import org.jhotdraw8.base.net.UriUtil; -import org.jhotdraw8.collection.ChampMap; import org.jhotdraw8.fxbase.concurrent.SimpleWorkState; import org.jhotdraw8.fxbase.concurrent.WorkState; +import org.jhotdraw8.icollection.ChampMap; import java.net.URI; import java.util.MissingResourceException; diff --git a/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/file/RevertFileAction.java b/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/file/RevertFileAction.java index 487d5b268..09dcec103 100755 --- a/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/file/RevertFileAction.java +++ b/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/action/file/RevertFileAction.java @@ -13,9 +13,9 @@ import org.jhotdraw8.application.ApplicationLabels; import org.jhotdraw8.application.FileBasedActivity; import org.jhotdraw8.application.action.AbstractActivityAction; -import org.jhotdraw8.collection.ChampMap; import org.jhotdraw8.fxbase.concurrent.SimpleWorkState; import org.jhotdraw8.fxbase.concurrent.WorkState; +import org.jhotdraw8.icollection.ChampMap; import java.net.URI; import java.util.Optional; diff --git a/org.jhotdraw8.collection/pom.xml b/org.jhotdraw8.collection/pom.xml index 3f12b309f..ad6ad83bc 100644 --- a/org.jhotdraw8.collection/pom.xml +++ b/org.jhotdraw8.collection/pom.xml @@ -46,6 +46,11 @@ ${revision} + ch.randelshofer + org.jhotdraw8.icollection + ${revision} + + com.google.guava guava-testlib test diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/module-info.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/module-info.java index 3bd0445cf..130e05a64 100755 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/module-info.java +++ b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/module-info.java @@ -9,17 +9,13 @@ @SuppressWarnings("module") module org.jhotdraw8.collection { requires static org.jhotdraw8.annotation; + requires org.jhotdraw8.icollection; exports org.jhotdraw8.collection.enumerator; - exports org.jhotdraw8.collection.facade; exports org.jhotdraw8.collection.function; - exports org.jhotdraw8.collection.immutable; exports org.jhotdraw8.collection.iterator; exports org.jhotdraw8.collection.mapped; exports org.jhotdraw8.collection.primitive; - exports org.jhotdraw8.collection.readonly; exports org.jhotdraw8.collection.reflect; - exports org.jhotdraw8.collection.sequenced; - exports org.jhotdraw8.collection; exports org.jhotdraw8.collection.pair; exports org.jhotdraw8.collection.spliterator; exports org.jhotdraw8.collection.transform; diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AddOnlyChampSet.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AddOnlyChampSet.java deleted file mode 100644 index 20ac94422..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AddOnlyChampSet.java +++ /dev/null @@ -1,268 +0,0 @@ -/* - * @(#)AddOnlyChampSet.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableAddOnlySet; - -import java.util.Arrays; -import java.util.Objects; - -/** - * Implements the {@link ImmutableAddOnlySet} interface using a Compressed - * Hash-Array Mapped Prefix-tree (CHAMP). - *

- * References: - *

- *
Michael J. Steindorfer (2017). - * Efficient Immutable Collections.
- *
michael.steindorfer.name - * - *
The Capsule Hash Trie Collections Library. - *
Copyright (c) Michael Steindorfer. BSD-2-Clause License
- *
github.com - *
- * - * @param the element type - */ -public abstract class AddOnlyChampSet implements ImmutableAddOnlySet { - private static final int ENTRY_LENGTH = 1; - private static final int HASH_CODE_LENGTH = 32; - private static final int BIT_PARTITION_SIZE = 4; - private static final int BIT_PARTITION_MASK = (1 << BIT_PARTITION_SIZE) - 1; - - /** - * Constructs a new empty set. - */ - AddOnlyChampSet() { - } - - private static char mask(int bitpos) { - return (char) (1 << bitpos); - } - - private static int bitpos(int keyHash, int shift) { - return (keyHash >>> shift) & BIT_PARTITION_MASK; - } - - private static @NonNull AddOnlyChampSet mergeTwoKeyValPairs(@NonNull K key0, int keyHash0, - @NonNull K key1, int keyHash1, int shift) { - assert !(key0.equals(key1)); - - if (shift >= HASH_CODE_LENGTH) { - HashCollisionNode unchecked = new HashCollisionNode<>(keyHash0, key0, key1); - return unchecked; - } - - int mask0 = bitpos(keyHash0, shift); - int mask1 = bitpos(keyHash1, shift); - - if (mask0 != mask1) { - // both nodes fit on same level - final char dataMap = (char) (mask(mask0) | mask(mask1)); - - if (mask0 < mask1) { - return new BitmapIndexedNode<>((char) 0, dataMap, key0, key1); - } else { - return new BitmapIndexedNode<>((char) 0, dataMap, key1, key0); - } - } else { - final AddOnlyChampSet node = - mergeTwoKeyValPairs(key0, keyHash0, key1, keyHash1, shift + BIT_PARTITION_SIZE); - // values fit on next level - final char nodeMap = mask(mask0); - return new BitmapIndexedNode<>(nodeMap, (char) 0, node); - } - } - - /** - * Returns an empty set. - * - * @param the element type. - * @return an empty set. - */ - @SuppressWarnings("unchecked") - public static @NonNull AddOnlyChampSet of() { - return (AddOnlyChampSet) BitmapIndexedNode.EMPTY_NODE; - } - - /** - * Returns a set that contains the specified elements. - * - * @param elements the specified elements - * @param the element type. - * @return a set of the specified elements. - */ - @SuppressWarnings({"unchecked", "varargs"}) - @SafeVarargs - public static @NonNull AddOnlyChampSet of(E @NonNull ... elements) { - AddOnlyChampSet set = (AddOnlyChampSet) BitmapIndexedNode.EMPTY_NODE; - for (E e : elements) { - set = set.add(e); - } - return set; - } - - @Override - public @NonNull AddOnlyChampSet add(@NonNull E key) { - return updated(key, key.hashCode(), 0); - } - - abstract @NonNull AddOnlyChampSet updated(@NonNull E key, int keyHash, int shift); - - private static final class BitmapIndexedNode extends AddOnlyChampSet { - private static final @NonNull AddOnlyChampSet EMPTY_NODE = new BitmapIndexedNode<>((char) 0, (char) 0); - @NonNull - final Object[] nodes; - /** - * We use char as an unsigned short. - */ - private final char nodeMap; - /** - * We use char as an unsigned short. - */ - private final char dataMap; - - BitmapIndexedNode(char nodeMap, - char dataMap, @NonNull Object... nodes) { - this.nodeMap = nodeMap; - this.dataMap = dataMap; - this.nodes = nodes; - } - - @NonNull AddOnlyChampSet copyAndInsertValue(int mask, - @NonNull K key) { - final int idx = ENTRY_LENGTH * dataIndex(mask); - - // copy 'src' and insert 1 element(s) at position 'idx' - final Object[] src = this.nodes; - final Object[] dst = new Object[src.length + 1]; - System.arraycopy(src, 0, dst, 0, idx); - System.arraycopy(src, idx, dst, idx + 1, src.length - idx); - dst[idx] = key; - - return new BitmapIndexedNode<>(nodeMap, (char) (dataMap | mask), dst); - } - - @NonNull AddOnlyChampSet copyAndMigrateFromInlineToNode(int mask, @NonNull AddOnlyChampSet node) { - - final int idxOld = ENTRY_LENGTH * dataIndex(mask); - final int idxNew = this.nodes.length - ENTRY_LENGTH - nodeIndex(mask); - assert idxOld <= idxNew; - - // copy 'src' and remove 1 element(s) at position 'idxOld' and - // insert 1 element(s) at position 'idxNew' - final Object[] src = this.nodes; - final Object[] dst = new Object[src.length - 1 + 1]; - System.arraycopy(src, 0, dst, 0, idxOld); - System.arraycopy(src, idxOld + 1, dst, idxOld, idxNew - idxOld); - System.arraycopy(src, idxNew + 1, dst, idxNew + 1, src.length - idxNew - 1); - dst[idxNew] = node; - - return new BitmapIndexedNode<>((char) (nodeMap | mask), (char) (dataMap ^ mask), dst); - } - - @NonNull AddOnlyChampSet copyAndSetNode(int mask, - @NonNull AddOnlyChampSet newNode) { - - final int nodeIndex = nodeIndex(mask); - final int idx = this.nodes.length - 1 - nodeIndex; - - // copy 'src' and set 1 element(s) at position 'idx' - final Object[] src = this.nodes; - final Object[] dst = new Object[src.length]; - System.arraycopy(src, 0, dst, 0, src.length); - dst[idx] = newNode; - - return new BitmapIndexedNode<>(nodeMap, dataMap, dst); - } - - int dataIndex(int mask) { - return Integer.bitCount(dataMap & (mask - 1)); - } - - @SuppressWarnings("unchecked") - @NonNull K getKey(int index) { - return (K) nodes[ENTRY_LENGTH * index]; - } - - @SuppressWarnings("unchecked") - @NonNull AddOnlyChampSet getNode(int index) { - return (AddOnlyChampSet) nodes[nodes.length - 1 - index]; - } - - @NonNull AddOnlyChampSet nodeAt(int mask) { - return getNode(nodeIndex(mask)); - } - - int nodeIndex(int mask) { - return Integer.bitCount(nodeMap & (mask - 1)); - } - - @Override - @NonNull AddOnlyChampSet updated(@NonNull K key, int keyHash, - int shift) { - final int bitpos = bitpos(keyHash, shift); - final int mask = mask(bitpos); - - if ((dataMap & mask) != 0) { // in-place value - final int dataIndex = dataIndex(mask); - final K currentKey = getKey(dataIndex); - - if (Objects.equals(currentKey, key)) { - return this; - } else { - final AddOnlyChampSet subNodeNew = mergeTwoKeyValPairs(currentKey, - currentKey.hashCode(), key, keyHash, shift + BIT_PARTITION_SIZE); - return copyAndMigrateFromInlineToNode(mask, subNodeNew); - } - } else if ((nodeMap & mask) != 0) { // node (not value) - final AddOnlyChampSet subNode = nodeAt(mask); - final AddOnlyChampSet subNodeNew = - subNode.updated(key, keyHash, shift + BIT_PARTITION_SIZE); - - if (subNode != subNodeNew) { - return copyAndSetNode(mask, subNodeNew); - } else { - return this; - } - } else { - // no value - return copyAndInsertValue(mask, key); - } - } - - } - - private static final class HashCollisionNode extends AddOnlyChampSet { - private final @NonNull K[] keys; - private final int hash; - - - @SuppressWarnings("varargs") - @SafeVarargs - HashCollisionNode(int hash, @NonNull final K... keys) { - this.keys = keys; - this.hash = hash; - } - - @Override - @NonNull - AddOnlyChampSet updated(@NonNull K key, - int keyHash, int shift) { - assert this.hash == keyHash; - - for (K k : keys) { - if (Objects.equals(k, key)) { - return this; - } - } - - final K[] keysNew = Arrays.copyOf(keys, keys.length + 1); - keysNew[keys.length] = key; - return new HashCollisionNode<>(keyHash, keysNew); - } - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/ChampMap.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/ChampMap.java deleted file mode 100644 index e19f1239d..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/ChampMap.java +++ /dev/null @@ -1,341 +0,0 @@ -/* - * @(#)ChampMap.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.facade.ReadOnlySetFacade; -import org.jhotdraw8.collection.immutable.ImmutableMap; -import org.jhotdraw8.collection.impl.champ.*; -import org.jhotdraw8.collection.readonly.ReadOnlyMap; -import org.jhotdraw8.collection.readonly.ReadOnlySet; -import org.jhotdraw8.collection.serialization.MapSerializationProxy; -import org.jhotdraw8.collection.transform.Transformer; - -import java.io.ObjectStreamException; -import java.io.Serial; -import java.io.Serializable; -import java.util.AbstractMap.SimpleImmutableEntry; -import java.util.Iterator; -import java.util.Map; -import java.util.Objects; -import java.util.Spliterator; -import java.util.function.Function; - -/** - * Implements the {@link ImmutableMap} interface using a Compressed Hash-Array - * Mapped Prefix-tree (CHAMP). - *

- * Features: - *

    - *
  • supports up to 230 entries
  • - *
  • allows null keys and null values
  • - *
  • is immutable
  • - *
  • is thread-safe
  • - *
  • does not guarantee a specific iteration order
  • - *
- *

- * Performance characteristics: - *

    - *
  • put: O(1)
  • - *
  • remove: O(1)
  • - *
  • containsKey: O(1)
  • - *
  • toMutable: O(1) + O(log N) distributed across subsequent updates in the mutable copy
  • - *
  • clone: O(1)
  • - *
  • iterator.next(): O(1)
  • - *
- *

- * Implementation details: - *

- * This map performs read and write operations of single elements in O(1) time, - * and in O(1) space. - *

- * Uses a Compressed Hash-Array Mapped Prefix-tree (CHAMP) trie for storing - * the map entries. - *

- * The CHAMP trie contains nodes that may be shared with other maps. - *

- * If a write operation is performed on a node, then this map creates a - * copy of the node and of all parent nodes up to the root (copy-path-on-write). - * Since the CHAMP trie has a fixed maximal height, the cost is O(1). - *

- * This map can create a mutable copy of itself in O(1) time and O(1) space - * using method {@link #toMutable()}. The mutable copy shares its nodes - * with this map, until it has gradually replaced the nodes with exclusively - * owned nodes. - *

- * All operations on this map can be performed concurrently, without a need for - * synchronisation. - *

- * The immutable version of this map extends from the non-public class - * {@code ChampBitmapIndexNode}. This design safes 16 bytes for every instance, - * and reduces the number of redirections for finding an element in the - * collection by 1. - *

- * References: - *

- * Portions of the code in this class has been derived from 'The Capsule Hash Trie Collections Library'. - *

- *
Michael J. Steindorfer (2017). - * Efficient Immutable Collections.
- *
michael.steindorfer.name - *
The Capsule Hash Trie Collections Library. - *
Copyright (c) Michael Steindorfer. BSD-2-Clause License
- *
github.com - *
- * - * @param the key type - * @param the value type - */ -@SuppressWarnings("exports") -public class ChampMap extends BitmapIndexedNode> - implements ImmutableMap, Serializable { - /** - * We do not guarantee an iteration order. Make sure that nobody accidentally relies on it. - */ - static final int SALT = new java.util.Random().nextInt(); - private static final @NonNull ChampMap EMPTY = new ChampMap<>(BitmapIndexedNode.emptyNode(), 0); - @Serial - private static final long serialVersionUID = 0L; - final int size; - - ChampMap(@NonNull BitmapIndexedNode> root, int size) { - super(root.nodeMap(), root.dataMap(), root.mixed); - this.size = size; - } - - /** - * Returns an immutable copy of the provided map. - * - * @param c a map - * @param the key type - * @param the value type - * @return an immutable copy - */ - @SuppressWarnings("unchecked") - public static @NonNull ChampMap copyOf(@NonNull Iterable> c) { - return ChampMap.of().putAll(c); - } - - /** - * Returns an immutable copy of the provided map. - * - * @param map a map - * @param the key type - * @param the value type - * @return an immutable copy - */ - public static @NonNull ChampMap copyOf(@NonNull Map map) { - return ChampMap.of().putAll(map); - } - - static boolean entryKeyEquals(SimpleImmutableEntry a, SimpleImmutableEntry b) { - return Objects.equals(a.getKey(), b.getKey()); - } - - static int keyHash(Object e) { - return SALT ^ Objects.hashCode(e); - } - - static int entryKeyHash(SimpleImmutableEntry e) { - return SALT ^ Objects.hashCode(e.getKey()); - } - - /** - * Returns an empty immutable map. - * - * @param the key type - * @param the value type - * @return an empty immutable map - */ - @SuppressWarnings("unchecked") - public static @NonNull ChampMap of() { - return (ChampMap) ChampMap.EMPTY; - } - - @Nullable - static SimpleImmutableEntry updateEntry(@Nullable SimpleImmutableEntry oldv, @Nullable SimpleImmutableEntry newv) { - return Objects.equals(oldv.getValue(), newv.getValue()) ? oldv : newv; - } - - /** - * {@inheritDoc} - */ - @Override - public @NonNull ChampMap clear() { - return isEmpty() ? this : of(); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean containsKey(@Nullable Object o) { - @SuppressWarnings("unchecked") final K key = (K) o; - return find(new SimpleImmutableEntry<>(key, null), keyHash(key), 0, - ChampMap::entryKeyEquals) != Node.NO_DATA; - } - - @Override - public boolean equals(@Nullable Object other) { - if (other == this) { - return true; - } - if (other instanceof ChampMap) { - ChampMap that = (ChampMap) other; - return size == that.size && equivalent(that); - } - return ReadOnlyMap.mapEquals(this, other); - } - - @Override - @SuppressWarnings("unchecked") - public V get(Object o) { - Object result = find( - new SimpleImmutableEntry<>((K) o, null), keyHash(o), 0, ChampMap::entryKeyEquals); - return result == Node.NO_DATA || result == null ? null : ((SimpleImmutableEntry) result).getValue(); - } - - @Override - public int hashCode() { - return ReadOnlyMap.iteratorToHashCode(iterator()); - } - - @Override - public boolean isEmpty() { - return size == 0; - } - - @Override - public @NonNull Iterator> iterator() { - return new ChampIterator<>(this, null); - } - - @Override - public long maxSize() { - return 1 << 30; - } - - @Override - public @NonNull ChampMap put(@NonNull K key, @Nullable V value) { - var details = new ChangeEvent>(); - var newRootNode = put(null, new SimpleImmutableEntry<>(key, value), - keyHash(key), 0, details, - ChampMap::updateEntry, ChampMap::entryKeyEquals, ChampMap::entryKeyHash); - if (details.isModified()) { - return new ChampMap<>(newRootNode, details.isReplaced() ? size : size + 1); - } - return this; - } - - @Override - public @NonNull ChampMap putAll(@NonNull Map m) { - return (ChampMap) ImmutableMap.super.putAll(m); - } - - @SuppressWarnings("unchecked") - @Override - public @NonNull ChampMap putAll(@NonNull Iterable> c) { - var m = toMutable(); - m.putAll(c); - return m.toImmutable(); - } - - @Override - public @NonNull ChampMap remove(@NonNull K key) { - int keyHash = keyHash(key); - var details = new ChangeEvent>(); - var newRootNode = - remove(null, new SimpleImmutableEntry<>(key, null), keyHash, 0, details, - ChampMap::entryKeyEquals); - if (details.isModified()) { - return size == 1 ? ChampMap.of() : new ChampMap<>(newRootNode, size - 1); - } - return this; - } - - @SuppressWarnings("unchecked") - @Override - public @NonNull ChampMap removeAll(@NonNull Iterable c) { - var m = toMutable(); - m.removeAll(c); - return m.toImmutable(); - } - - @SuppressWarnings("unchecked") - @Override - public @NonNull ChampMap retainAll(@NonNull Iterable c) { - var m = toMutable(); - m.retainAll(c); - return m.toImmutable(); - } - - @Override - public @NonNull ReadOnlySet readOnlyKeySet() { - return new ReadOnlySetFacade<>( - () -> new ChampIterator<>(this, Map.Entry::getKey), - this::size, - this::containsKey - ); - } - - @Override - public int size() { - return size; - } - public @NonNull Spliterator> spliterator() { - return new ChampSpliterator<>(this, null, size(), Spliterator.SIZED | Spliterator.IMMUTABLE | Spliterator.DISTINCT); - } - - /** - * Creates a mutable copy of this map. - * - * @return a mutable CHAMP map - */ - @Override - public @NonNull MutableChampMap toMutable() { - return new MutableChampMap<>(this); - } - - @Override - public @NonNull MutableChampMap asMap() { - return new MutableChampMap<>(this); - } - - @Override - public Transformer> transformed() { - return this::transform; - } - - private R transform(Function, ? extends R> f) { - return f.apply(this); - } - - @Override - public @NonNull String toString() { - return ReadOnlyMap.mapToString(this); - } - - @Serial - private @NonNull Object writeReplace() throws ObjectStreamException { - return new SerializationProxy<>(this.toMutable()); - } - - static class SerializationProxy extends MapSerializationProxy { - @Serial - private static final long serialVersionUID = 0L; - - SerializationProxy(Map target) { - super(target); - } - - @Serial - @Override - protected @NonNull Object readResolve() { - return ChampMap.of().putAll(deserialized); - } - } - -} \ No newline at end of file diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/ChampSet.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/ChampSet.java deleted file mode 100644 index 96d5501e5..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/ChampSet.java +++ /dev/null @@ -1,289 +0,0 @@ -/* - * @(#)ChampSet.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection; - - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableSet; -import org.jhotdraw8.collection.impl.champ.*; -import org.jhotdraw8.collection.readonly.ReadOnlyCollection; -import org.jhotdraw8.collection.readonly.ReadOnlySet; -import org.jhotdraw8.collection.serialization.SetSerializationProxy; -import org.jhotdraw8.collection.transform.Transformer; - -import java.io.Serial; -import java.io.Serializable; -import java.util.*; -import java.util.function.Function; - - -/** - * Implements the {@link ImmutableSet} interface using a Compressed Hash-Array - * Mapped Prefix-tree (CHAMP). - *

- * Features: - *

    - *
  • supports up to 230 entries
  • - *
  • allows null elements
  • - *
  • is immutable
  • - *
  • is thread-safe
  • - *
  • does not guarantee a specific iteration order
  • - *
- *

- * Performance characteristics: - *

    - *
  • add: O(1)
  • - *
  • remove: O(1)
  • - *
  • contains: O(1)
  • - *
  • toMutable: O(1)
  • - *
  • clone: O(1)
  • - *
  • iterator.next(): O(1)
  • - *
- *

- * Implementation details: - *

- * This set performs read and write operations of single elements in O(1) time, - * and in O(1) space. - *

- * Uses a Compressed Hash-Array Mapped Prefix-tree (CHAMP) trie for storing - * the set elements. - *

- * The CHAMP trie contains nodes that may be shared with other sets. - *

- * If a write operation is performed on a node, then this set creates a - * copy of the node and of all parent nodes up to the root (copy-path-on-write). - * Since the CHAMP trie has a fixed maximal height, the cost is O(1). - *

- * The immutable version of this set extends from the non-public class - * {@code ChampBitmapIndexNode}. This design safes 16 bytes for every instance, - * and reduces the number of redirections for finding an element in the - * collection by 1. - *

- * References: - *

- * Portions of the code in this class has been derived from 'The Capsule Hash Trie Collections Library'. - *

- *
Michael J. Steindorfer (2017). - * Efficient Immutable Collections.
- *
michael.steindorfer.name
- * - *
The Capsule Hash Trie Collections Library. - *
Copyright (c) Michael Steindorfer. BSD-2-Clause License
- *
github.com
- *
- * - * @param the element type - */ -@SuppressWarnings("exports") -public class ChampSet extends BitmapIndexedNode implements ImmutableSet, Serializable { - private static final @NonNull ChampSet EMPTY = new ChampSet<>(BitmapIndexedNode.emptyNode(), 0); - @Serial - private static final long serialVersionUID = 0L; - /** - * We do not guarantee an iteration order. Make sure that nobody accidentally relies on it. - */ - static final int SALT = 0;// new Random().nextInt(); - /** - * The size of the set. - */ - final int size; - - ChampSet(@NonNull BitmapIndexedNode root, int size) { - super(root.nodeMap(), root.dataMap(), root.mixed); - this.size = size; - } - - - /** - * Returns an immutable set that contains the provided elements. - * - * @param c an iterable - * @param the element type - * @return an immutable set of the provided elements - */ - public static @NonNull ChampSet copyOf(@NonNull Iterable c) { - return ChampSet.of().addAll(c); - } - - /** - * Returns an empty immutable set. - * - * @param the element type - * @return an empty immutable set - */ - @SuppressWarnings("unchecked") - public static @NonNull ChampSet of() { - return ((ChampSet) ChampSet.EMPTY); - } - - /** - * Returns an immutable set that contains the provided elements. - * - * @param elements elements - * @param the element type - * @return an immutable set of the provided elements - */ - @SuppressWarnings({"varargs"}) - @SafeVarargs - public static @NonNull ChampSet of(@NonNull E @Nullable ... elements) { - Objects.requireNonNull(elements, "elements is null"); - return ChampSet.of().addAll(Arrays.asList(elements)); - } - - @Override - public @NonNull ChampSet add(@Nullable E element) { - int keyHash = keyHash(element); - ChangeEvent details = new ChangeEvent<>(); - BitmapIndexedNode newRootNode = put(null, element, keyHash, 0, details, ChampSet::updateElement, Objects::equals, ChampSet::keyHash); - if (details.isModified()) { - return new ChampSet<>(newRootNode, size + 1); - } - return this; - } - - @Override - public @NonNull ChampSet addAll(@NonNull Iterable c) { - var m = toMutable(); - m.addAll(c); - return m.toImmutable(); - } - - - /** - * {@inheritDoc} - */ - @Override - public @NonNull ChampSet clear() { - return isEmpty() ? this : of(); - } - - @Override - @SuppressWarnings("unchecked") - public boolean contains(@Nullable Object o) { - return find((E) o, keyHash(o), 0, Objects::equals) != Node.NO_DATA; - } - - @Override - public boolean equals(@Nullable Object other) { - if (other == this) { - return true; - } - if (other == null) { - return false; - } - if (other instanceof ChampSet) { - ChampSet that = (ChampSet) other; - return size == that.size && equivalent(that); - } - return ReadOnlySet.setEquals(this, other); - } - - /** - * Update function for a set: we always keep the old element. - * - * @param oldElement the old element - * @param newElement the new element - * @param the element type - * @return always returns the old element - */ - static E updateElement(E oldElement, E newElement) { - return oldElement; - } - - @Override - public int hashCode() { - return ReadOnlySet.iteratorToHashCode(iterator()); - } - - @Override - public @NonNull Iterator iterator() { - return new ChampIterator<>(this, null); - } - - static int keyHash(Object e) { - return SALT ^ Objects.hashCode(e); - } - - @Override - public long maxSize() { - return 1 << 30; - } - - - @Override - public @NonNull ChampSet remove(@NonNull E key) { - int keyHash = keyHash(key); - ChangeEvent details = new ChangeEvent<>(); - BitmapIndexedNode newRootNode = remove(null, key, keyHash, 0, details, Objects::equals); - if (details.isModified()) { - return size == 1 ? ChampSet.of() : new ChampSet<>(newRootNode, size - 1); - } - return this; - } - - @Override - public @NonNull ChampSet removeAll(@NonNull Iterable c) { - var m = toMutable(); - m.removeAll(c); - return m.toImmutable(); - } - - - @Override - public @NonNull ChampSet retainAll(@NonNull Iterable c) { - var m = toMutable(); - m.retainAll(c); - return m.toImmutable(); - } - - @Override - public int size() { - return size; - } - - public @NonNull Spliterator spliterator() { - return new ChampSpliterator<>(this, null, size, Spliterator.SIZED | Spliterator.IMMUTABLE | Spliterator.DISTINCT); - } - - @Override - public @NonNull MutableChampSet toMutable() { - return new MutableChampSet<>(this); - } - - @Override - public Transformer> transformed() { - return this::transform; - } - - private R transform(Function, ? extends R> f) { - return f.apply(this); - } - - @Override - public @NonNull String toString() { - return ReadOnlyCollection.iterableToString(this); - } - - @Serial - private @NonNull Object writeReplace() { - return new SerializationProxy<>(this.toMutable()); - } - - private static class SerializationProxy extends SetSerializationProxy { - @Serial - private static final long serialVersionUID = 0L; - - protected SerializationProxy(@NonNull Set target) { - super(target); - } - - @Serial - @Override - protected @NonNull Object readResolve() { - return ChampSet.copyOf(deserialized); - } - } -} \ No newline at end of file diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MapEntries.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MapEntries.java deleted file mode 100644 index 8dab27b99..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MapEntries.java +++ /dev/null @@ -1,406 +0,0 @@ -/* - * @(#)MapEntries.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; - -import java.util.*; -import java.util.AbstractMap.SimpleImmutableEntry; -import java.util.function.Supplier; - -/** - * Provides static methods for creating a list of map entries. - */ -public class MapEntries { - /** - * Don't let anyone instantiate this class. - */ - private MapEntries() { - } - - - /** - * Returns a list containing 0 map entries. - *

- * Keys and values can be null. - * - * @return a list containing the entries - */ - public static @NonNull List> of() { - return new ArrayList<>(); - } - - /** - * Returns a list containing 1 map entry. - *

- * Key and value can be null. - * - * @param the key type - * @param the value type - * @param k1 key 1 - * @param v1 value 1 - * @return a list containing the entries - */ - public static @NonNull List> of(K k1, V v1) { - ArrayList> l = new ArrayList<>(); - l.add(new SimpleImmutableEntry<>(k1, v1)); - return l; - } - - - /** - * Returns a list containing 2 map entries. - *

- * Keys and values can be null. - * - * @param the key type - * @param the value type - * @param k1 key 1 - * @param v1 value 1 - * @param k2 key 2 - * @param v2 value 2 - * @return a list containing the entries - */ - public static @NonNull List> of(K k1, V v1, K k2, V v2) { - ArrayList> l = new ArrayList<>(); - l.add(new SimpleImmutableEntry<>(k1, v1)); - l.add(new SimpleImmutableEntry<>(k2, v2)); - return l; - } - - /** - * Returns a list containing 3 map entries. - *

- * Keys and values can be null. - * - * @param the key type - * @param the value type - * @param k1 key 1 - * @param v1 value 1 - * @param k2 key 2 - * @param v2 value 2 - * @param k3 key 3 - * @param v3 value 3 - * @return a list containing the entries - */ - public static @NonNull List> of(K k1, V v1, K k2, V v2, K k3, V v3) { - ArrayList> l = new ArrayList<>(); - l.add(new SimpleImmutableEntry<>(k1, v1)); - l.add(new SimpleImmutableEntry<>(k2, v2)); - l.add(new SimpleImmutableEntry<>(k3, v3)); - return l; - } - - - /** - * Returns a list containing 4 map entries. - *

- * Keys and values can be null. - * - * @param the key type - * @param the value type - * @param k1 key 1 - * @param v1 value 1 - * @param k2 key 2 - * @param v2 value 2 - * @param k3 key 3 - * @param v3 value 3 - * @param k4 key 4 - * @param v4 value 4 - * @return a list containing the entries - */ - public static @NonNull List> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { - ArrayList> l = new ArrayList<>(); - l.add(new SimpleImmutableEntry<>(k1, v1)); - l.add(new SimpleImmutableEntry<>(k2, v2)); - l.add(new SimpleImmutableEntry<>(k3, v3)); - l.add(new SimpleImmutableEntry<>(k4, v4)); - return l; - } - - /** - * Returns a list containing 5 map entries. - *

- * Keys and values can be null. - * - * @param the key type - * @param the value type - * @param k1 key 1 - * @param v1 value 1 - * @param k2 key 2 - * @param v2 value 2 - * @param k3 key 3 - * @param v3 value 3 - * @param k4 key 4 - * @param v4 value 4 - * @param k5 key 5 - * @param v5 value 5 - * @return a list containing the entries - */ - public static @NonNull List> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) { - ArrayList> l = new ArrayList<>(); - l.add(new SimpleImmutableEntry<>(k1, v1)); - l.add(new SimpleImmutableEntry<>(k2, v2)); - l.add(new SimpleImmutableEntry<>(k3, v3)); - l.add(new SimpleImmutableEntry<>(k4, v4)); - l.add(new SimpleImmutableEntry<>(k5, v5)); - return l; - } - - /** - * Returns a list containing 6 map entries. - *

- * Keys and values can be null. - * - * @param the key type - * @param the value type - * @param k1 key 1 - * @param v1 value 1 - * @param k2 key 2 - * @param v2 value 2 - * @param k3 key 3 - * @param v3 value 3 - * @param k4 key 4 - * @param v4 value 4 - * @param k5 key 5 - * @param v5 value 5 - * @param k6 key 6 - * @param v6 value 6 - * @return a list containing the entries - */ - public static @NonNull List> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, - K k6, V v6) { - ArrayList> l = new ArrayList<>(); - l.add(new SimpleImmutableEntry<>(k1, v1)); - l.add(new SimpleImmutableEntry<>(k2, v2)); - l.add(new SimpleImmutableEntry<>(k3, v3)); - l.add(new SimpleImmutableEntry<>(k4, v4)); - l.add(new SimpleImmutableEntry<>(k5, v5)); - l.add(new SimpleImmutableEntry<>(k6, v6)); - return l; - } - - /** - * Returns a list containing 7 map entries. - *

- * Keys and values can be null. - * - * @param the key type - * @param the value type - * @param k1 key 1 - * @param v1 value 1 - * @param k2 key 2 - * @param v2 value 2 - * @param k3 key 3 - * @param v3 value 3 - * @param k4 key 4 - * @param v4 value 4 - * @param k5 key 5 - * @param v5 value 5 - * @param k6 key 6 - * @param v6 value 6 - * @param k7 key 7 - * @param v7 value 7 - * @return a list containing the entries - */ - public static @NonNull List> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, - K k6, V v6, K k7, V v7) { - ArrayList> l = new ArrayList<>(); - l.add(new SimpleImmutableEntry<>(k1, v1)); - l.add(new SimpleImmutableEntry<>(k2, v2)); - l.add(new SimpleImmutableEntry<>(k3, v3)); - l.add(new SimpleImmutableEntry<>(k4, v4)); - l.add(new SimpleImmutableEntry<>(k5, v5)); - l.add(new SimpleImmutableEntry<>(k6, v6)); - l.add(new SimpleImmutableEntry<>(k7, v7)); - return l; - } - - /** - * Returns a list containing 8 map entries. - *

- * Keys and values can be null. - * - * @param the key type - * @param the value type - * @param k1 key 1 - * @param v1 value 1 - * @param k2 key 2 - * @param v2 value 2 - * @param k3 key 3 - * @param v3 value 3 - * @param k4 key 4 - * @param v4 value 4 - * @param k5 key 5 - * @param v5 value 5 - * @param k6 key 6 - * @param v6 value 6 - * @param k7 key 7 - * @param v7 value 7 - * @param k8 key 8 - * @param v8 value 8 - * @return a list containing the entries - */ - public static @NonNull List> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, - K k6, V v6, K k7, V v7, K k8, V v8) { - ArrayList> l = new ArrayList<>(); - l.add(new SimpleImmutableEntry<>(k1, v1)); - l.add(new SimpleImmutableEntry<>(k2, v2)); - l.add(new SimpleImmutableEntry<>(k3, v3)); - l.add(new SimpleImmutableEntry<>(k4, v4)); - l.add(new SimpleImmutableEntry<>(k5, v5)); - l.add(new SimpleImmutableEntry<>(k6, v6)); - l.add(new SimpleImmutableEntry<>(k7, v7)); - l.add(new SimpleImmutableEntry<>(k8, v8)); - return l; - } - - /** - * Returns a list containing 9 map entries. - *

- * Keys and values can be null. - * - * @param the key type - * @param the value type - * @param k1 key 1 - * @param v1 value 1 - * @param k2 key 2 - * @param v2 value 2 - * @param k3 key 3 - * @param v3 value 3 - * @param k4 key 4 - * @param v4 value 4 - * @param k5 key 5 - * @param v5 value 5 - * @param k6 key 6 - * @param v6 value 6 - * @param k7 key 7 - * @param v7 value 7 - * @param k8 key 8 - * @param v8 value 8 - * @param k9 key 9 - * @param v9 value 9 - * @return a list containing the entries - */ - public static @NonNull List> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, - K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9) { - ArrayList> l = new ArrayList<>(); - l.add(new SimpleImmutableEntry<>(k1, v1)); - l.add(new SimpleImmutableEntry<>(k2, v2)); - l.add(new SimpleImmutableEntry<>(k3, v3)); - l.add(new SimpleImmutableEntry<>(k4, v4)); - l.add(new SimpleImmutableEntry<>(k5, v5)); - l.add(new SimpleImmutableEntry<>(k6, v6)); - l.add(new SimpleImmutableEntry<>(k7, v7)); - l.add(new SimpleImmutableEntry<>(k8, v8)); - l.add(new SimpleImmutableEntry<>(k9, v9)); - return l; - } - - /** - * Returns a list containing 10 map entries. - *

- * Keys and values can be null. - * - * @param k1 key 1 - * @param v1 value 1 - * @param k2 key 2 - * @param v2 value 2 - * @param k3 key 3 - * @param v3 value 3 - * @param k4 key 4 - * @param v4 value 4 - * @param k5 key 5 - * @param v5 value 5 - * @param k6 key 6 - * @param v6 value 6 - * @param k7 key 7 - * @param v7 value 7 - * @param k8 key 8 - * @param v8 value 8 - * @param k9 key 9 - * @param v9 value 9 - * @param k10 key 10 - * @param v10 value 10 - * @param the key type - * @param the value type - * @return a list containing the entries - */ - public static @NonNull List> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, - K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9, K k10, V v10) { - ArrayList> l = new ArrayList<>(); - l.add(new SimpleImmutableEntry<>(k1, v1)); - l.add(new SimpleImmutableEntry<>(k2, v2)); - l.add(new SimpleImmutableEntry<>(k3, v3)); - l.add(new SimpleImmutableEntry<>(k4, v4)); - l.add(new SimpleImmutableEntry<>(k5, v5)); - l.add(new SimpleImmutableEntry<>(k6, v6)); - l.add(new SimpleImmutableEntry<>(k7, v7)); - l.add(new SimpleImmutableEntry<>(k8, v8)); - l.add(new SimpleImmutableEntry<>(k9, v9)); - l.add(new SimpleImmutableEntry<>(k10, v10)); - return l; - } - - /** - * Returns a list containing the specified map entries. - *

- * Keys and values can be null. - * - * @param entries the entries - * @param the key type - * @param the value type - * @return a list containing the entries - */ - @SafeVarargs - @SuppressWarnings({"varargs", "unchecked"}) - public static @NonNull List> ofEntries(Map.Entry... entries) { - return (List>) (List) Arrays.asList(entries); - } - - /** - * Creates a new linked hash map from a list of entries. - * - * @param l a list of entries - * @param the key type - * @param the value type - * @return a new linked hash map - */ - public static LinkedHashMap linkedHashMap(@NonNull List> l) { - return map(LinkedHashMap::new, l); - } - - /** - * Creates a new map from a list of entries. - * - * @param l a list of entries - * @param the key type - * @param the value type - * @return a new linked hash map - */ - public static > M map(@NonNull Supplier factory, @NonNull List> l) { - M m = factory.get(); - for (Map.Entry entry : l) { - m.put(entry.getKey(), entry.getValue()); - } - return m; - } - - /** - * Creates a new map entry. - *

- * Key and value can be null. - * - * @param k the key - * @param v the value - * @param the key type - * @param the value type - * @return a new map entry - */ - public static Map.@NonNull Entry entry(K k, V v) { - return new AbstractMap.SimpleEntry<>(k, v); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableChampMap.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableChampMap.java deleted file mode 100644 index b4ff9ee23..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableChampMap.java +++ /dev/null @@ -1,351 +0,0 @@ -/* - * @(#)MutableChampMap.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.facade.SetFacade; -import org.jhotdraw8.collection.impl.champ.*; -import org.jhotdraw8.collection.iterator.FailFastIterator; -import org.jhotdraw8.collection.readonly.ReadOnlyCollection; -import org.jhotdraw8.collection.readonly.ReadOnlyMap; -import org.jhotdraw8.collection.serialization.MapSerializationProxy; -import org.jhotdraw8.collection.spliterator.FailFastSpliterator; - -import java.io.Serial; -import java.util.*; - -/** - * Implements the {@link Map} interface using a Compressed Hash-Array Mapped - * Prefix-tree (CHAMP). - *

- * Features: - *

    - *
  • allows null keys and null values
  • - *
  • is mutable
  • - *
  • is not thread-safe
  • - *
  • does not guarantee a specific iteration order
  • - *
- *

- * Performance characteristics: - *

    - *
  • put: O(1)
  • - *
  • remove: O(1)
  • - *
  • containsKey: O(1)
  • - *
  • toImmutable: O(1) + O(log N) distributed across subsequent updates in - * this map
  • - *
  • clone: O(1) + O(log N) distributed across subsequent updates in this - * map and in the clone
  • - *
  • iterator.next: O(1)
  • - *
- *

- * Implementation details: - *

- * See description at {@link ChampMap}. - *

- * References: - *

- * Portions of the code in this class has been derived from 'The Capsule Hash Trie Collections Library'. - *

- *
Michael J. Steindorfer (2017). - * Efficient Immutable Collections.
- *
michael.steindorfer.name - *
The Capsule Hash Trie Collections Library. - *
Copyright (c) Michael Steindorfer. BSD-2-Clause License
- *
github.com - *
- * - * @param the key type - * @param the value type - */ -public class MutableChampMap extends AbstractMutableChampMap> { - @Serial - private static final long serialVersionUID = 0L; - - /** - * Constructs a new empty map. - */ - public MutableChampMap() { - root = BitmapIndexedNode.emptyNode(); - } - - public MutableChampMap(@NonNull Map m) { - if (m instanceof MutableChampMap) { - @SuppressWarnings("unchecked") - MutableChampMap that = (MutableChampMap) m; - this.root = that.root; - this.size = that.size; - this.modCount = 0; - } else { - this.root = BitmapIndexedNode.emptyNode(); - this.putAll(m); - } - } - - public MutableChampMap(@NonNull Iterable> m) { - this.root = BitmapIndexedNode.emptyNode(); - for (Entry e : m) { - this.put(e.getKey(), e.getValue()); - } - } - - public MutableChampMap(@NonNull ReadOnlyMap m) { - if (m instanceof ChampMap) { - @SuppressWarnings("unchecked") - ChampMap that = (ChampMap) m; - this.root = that; - this.size = that.size(); - } else { - this.root = BitmapIndexedNode.emptyNode(); - this.putAll(m.asMap()); - } - } - - /** - * Removes all entries from this map. - */ - @Override - public void clear() { - root = BitmapIndexedNode.emptyNode(); - size = 0; - modCount++; - } - - /** - * Returns a shallow copy of this map. - */ - @Override - public @NonNull MutableChampMap clone() { - return (MutableChampMap) super.clone(); - } - - - @Override - @SuppressWarnings("unchecked") - public boolean containsKey(@Nullable Object o) { - return root.find(new AbstractMap.SimpleImmutableEntry<>((K) o, null), - ChampMap.keyHash(o), 0, - ChampMap::entryKeyEquals) != Node.NO_DATA; - } - - @Override - public @NonNull Iterator> iterator() { - return new FailFastIterator<>( - new ChampIterator, Entry>(root, - e -> new MutableMapEntry<>(this::iteratorPutIfPresent, e.getKey(), e.getValue())), - this::iteratorRemove, this::getModCount - ); - } - - @Override - public @NonNull Spliterator> spliterator() { - return new FailFastSpliterator<>( - new ChampSpliterator<>(root, - e -> new MutableMapEntry<>(this::iteratorPutIfPresent, e.getKey(), e.getValue()), - size(), Spliterator.SIZED | Spliterator.DISTINCT), - this::getModCount); - } - - /** - * Returns a {@link Set} view of the entries contained in this map. - * - * @return a view of the entries contained in this map - */ - @Override - public @NonNull Set> entrySet() { - return new SetFacade<>( - this::iterator, - this::spliterator, - this::size, - this::containsEntry, - this::clear, - null, - this::removeEntry - ); - } - - /** - * Returns the value to which the specified key is mapped, - * or {@code null} if this map contains no entry for the key. - * - * @param o the key whose associated value is to be returned - * @return the associated value or null - */ - @Override - @SuppressWarnings("unchecked") - public @Nullable V get(Object o) { - Object result = root.find(new AbstractMap.SimpleImmutableEntry<>((K) o, null), - ChampMap.keyHash(o), 0, ChampMap::entryKeyEquals); - return result == Node.NO_DATA || result == null ? null : ((SimpleImmutableEntry) result).getValue(); - } - - private void iteratorPutIfPresent(@Nullable K k, @Nullable V v) { - if (containsKey(k)) { - owner = null; - put(k, v); - } - } - - private void iteratorRemove(Map.Entry entry) { - owner = null; - remove(entry.getKey()); - } - - @Override - public long maxSize() { - return 1 << 30; - } - - @Override - public V put(K key, V value) { - SimpleImmutableEntry oldValue = putEntry(key, value).getOldData(); - return oldValue == null ? null : oldValue.getValue(); - } - - @Override - @SuppressWarnings("unchecked") - public boolean putAll(@NonNull Iterable> c) { - if (c instanceof MutableChampMap m) { - c = (Iterable>) m.toImmutable(); - } - if (isEmpty() && c instanceof ChampMap that) { - if (that.isEmpty()) { - return false; - } - root = (BitmapIndexedNode>) (BitmapIndexedNode) that; - size = that.size; - modCount++; - return true; - } - if (c instanceof ChampMap that) { - var bulkChange = new BulkChangeEvent(); - var newRootNode = root.putAll(getOrCreateOwner(), (Node>) (Node) that, 0, bulkChange, ChampMap::updateEntry, ChampMap::entryKeyEquals, - ChampMap::entryKeyHash, new ChangeEvent<>()); - if (bulkChange.inBoth == that.size() && !bulkChange.replaced) { - return false; - } - root = newRootNode; - size += that.size - bulkChange.inBoth; - modCount++; - return true; - } - return super.putAll(c); - } - - @NonNull - ChangeEvent> putEntry(@Nullable K key, @Nullable V val) { - int keyHash = ChampMap.keyHash(key); - ChangeEvent> details = new ChangeEvent<>(); - root = root.put(getOrCreateOwner(), new AbstractMap.SimpleImmutableEntry<>(key, val), keyHash, 0, details, - ChampMap::updateEntry, - ChampMap::entryKeyEquals, - ChampMap::entryKeyHash); - if (details.isModified() && !details.isReplaced()) { - size += 1; - modCount++; - } - return details; - } - - @Override - public V remove(Object o) { - @SuppressWarnings("unchecked") final K key = (K) o; - SimpleImmutableEntry oldValue = removeKey(key).getOldData(); - return oldValue == null ? null : oldValue.getValue(); - } - - @SuppressWarnings("unchecked") - @Override - public boolean removeAll(@NonNull Iterable c) { - return super.removeAll(c); - } - - @SuppressWarnings("unchecked") - @Override - public boolean retainAll(@NonNull Iterable c) { - if (isEmpty()) { - return false; - } - if ((c instanceof Collection cc && cc.isEmpty()) - || (c instanceof ReadOnlyCollection rc) && rc.isEmpty()) { - clear(); - return true; - } - BulkChangeEvent bulkChange = new BulkChangeEvent(); - BitmapIndexedNode> newRootNode; - if (c instanceof Collection that) { - newRootNode = root.filterAll(getOrCreateOwner(), e -> that.contains(e.getKey()), 0, bulkChange); - } else if (c instanceof ReadOnlyCollection that) { - newRootNode = root.filterAll(getOrCreateOwner(), e -> that.contains(e.getKey()), 0, bulkChange); - } else { - HashSet that = new HashSet<>(); - c.forEach(that::add); - newRootNode = root.filterAll(getOrCreateOwner(), that::contains, 0, bulkChange); - } - if (bulkChange.removed == 0) { - return false; - } - root = newRootNode; - size -= bulkChange.removed; - modCount++; - return true; - } - - @NonNull - ChangeEvent> removeKey(K key) { - int keyHash = ChampMap.keyHash(key); - ChangeEvent> details = new ChangeEvent<>(); - root = root.remove(getOrCreateOwner(), new AbstractMap.SimpleImmutableEntry<>(key, null), keyHash, 0, details, - ChampMap::entryKeyEquals); - if (details.isModified()) { - size = size - 1; - modCount++; - } - return details; - } - - @SuppressWarnings("unchecked") - protected boolean removeEntry(@Nullable Object o) { - if (containsEntry(o)) { - assert o != null; - @SuppressWarnings("unchecked") Entry entry = (Entry) o; - remove(entry.getKey()); - return true; - } - return false; - } - - /** - * Returns an immutable copy of this map. - * - * @return an immutable copy - */ - public @NonNull ChampMap toImmutable() { - owner = null; - return isEmpty() ? ChampMap.of() - : root instanceof ChampMap m ? m : new ChampMap<>(root, size); - } - - @Serial - private @NonNull Object writeReplace() { - return new SerializationProxy<>(this); - } - - private static class SerializationProxy extends MapSerializationProxy { - @Serial - private static final long serialVersionUID = 0L; - - protected SerializationProxy(Map target) { - super(target); - } - - @Serial - @Override - protected @NonNull Object readResolve() { - return new MutableChampMap<>(deserialized); - } - } -} \ No newline at end of file diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableChampSet.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableChampSet.java deleted file mode 100644 index 593608bd1..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableChampSet.java +++ /dev/null @@ -1,334 +0,0 @@ -/* - * @(#)MutableChampSet.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.impl.IdentityObject; -import org.jhotdraw8.collection.impl.champ.*; -import org.jhotdraw8.collection.iterator.FailFastIterator; -import org.jhotdraw8.collection.readonly.ReadOnlyCollection; -import org.jhotdraw8.collection.serialization.SetSerializationProxy; -import org.jhotdraw8.collection.spliterator.FailFastSpliterator; - -import java.io.Serial; -import java.util.*; -import java.util.function.Function; - -import static org.jhotdraw8.collection.ChampSet.keyHash; - -/** - * Implements the {@link Set} interface using a Compressed Hash-Array Mapped - * Prefix-tree (CHAMP). - *

- * Features: - *

    - *
  • supports up to 230 elements
  • - *
  • allows null elements
  • - *
  • is mutable
  • - *
  • is not thread-safe
  • - *
  • does not guarantee a specific iteration order
  • - *
- *

- * Performance characteristics: - *

    - *
  • add: O(1)
  • - *
  • remove: O(1)
  • - *
  • contains: O(1)
  • - *
  • toImmutable: O(1) + O(log N) distributed across subsequent updates in - * this set
  • - *
  • clone: O(1) + O(log N) distributed across subsequent updates in this - * set and in the clone
  • - *
  • iterator.next: O(1)
  • - *
- *

- * Implementation details: - *

- * See description at {@link ChampSet}. - *

- * References: - *

- * Portions of the code in this class has been derived from 'The Capsule Hash Trie Collections Library'. - *

- *
Michael J. Steindorfer (2017). - * Efficient Immutable Collections.
- *
michael.steindorfer.name - *
The Capsule Hash Trie Collections Library. - *
Copyright (c) Michael Steindorfer. BSD-2-Clause License
- *
github.com - *
- * - * @param the element type - */ -public class MutableChampSet extends AbstractMutableChampSet { - @Serial - private static final long serialVersionUID = 0L; - - /** - * Constructs a new empty set. - */ - public MutableChampSet() { - root = BitmapIndexedNode.emptyNode(); - } - - /** - * Constructs a set containing the elements in the specified iterable. - * - * @param c an iterable - */ - @SuppressWarnings("unchecked") - public MutableChampSet(@NonNull Iterable c) { - if (c instanceof MutableChampSet) { - c = ((MutableChampSet) c).toImmutable(); - } - if (c instanceof ChampSet) { - ChampSet that = (ChampSet) c; - this.root = that; - this.size = that.size; - } else { - this.root = BitmapIndexedNode.emptyNode(); - addAll(c); - } - } - - @Override - public boolean add(@Nullable E e) { - ChangeEvent details = new ChangeEvent<>(); - root = root.put(makeOwner(), - e, ChampSet.keyHash(e), 0, details, - ChampSet::updateElement, - Objects::equals, ChampSet::keyHash); - if (details.isModified()) { - size++; - modCount++; - } - return details.isModified(); - } - - /** - * Adds all specified elements that are not already in this set. - * - * @param c an iterable of elements - * @return {@code true} if this set changed - */ - @SuppressWarnings("unchecked") - public boolean addAll(@NonNull Iterable c) { - if (c instanceof MutableChampSet m) { - c = (Iterable) m.toImmutable(); - } - if (c == root) { - return false; - } - if (isEmpty() && (c instanceof ChampSet cc)) { - root = (BitmapIndexedNode) cc; - size = cc.size; - return true; - } - IdentityObject currentOwner = makeOwner(); - ChangeEvent details = new ChangeEvent<>(); - int oldSize = size; - if (c instanceof ChampSet that) { - var bulkChange = new BulkChangeEvent(); - root = root.putAll(makeOwner(), (Node) that, 0, bulkChange, ChampSet::updateElement, Objects::equals, ChampSet::keyHash, new ChangeEvent<>()); - size += that.size - bulkChange.inBoth; - } else { - for (E e : c) { - details.resetModified(); - root = root.put(currentOwner, e, keyHash(e), 0, details, ChampSet::updateElement, Objects::equals, ChampSet::keyHash); - if (details.isModified()) { - size++; - } - } - } - modCount++; - return size != oldSize; - } - - @Override - public long maxSize() { - return 1 << 30; - } - - @Override - public boolean removeAll(@NonNull Collection c) { - return removeAll((Iterable) c); - } - - @Override - public boolean removeAll(@NonNull Iterable c) { - if (isEmpty() - || (c instanceof Collection cc) && cc.isEmpty() - || (c instanceof ReadOnlyCollection rc) && rc.isEmpty()) { - return false; - } - if (c == this) { - clear(); - return true; - } - if (c instanceof MutableChampSet m) { - c = m.toImmutable(); - } - if (c instanceof ChampSet that) { - BulkChangeEvent bulkChange = new BulkChangeEvent(); - @SuppressWarnings("unchecked") - BitmapIndexedNode newRootNode = root.removeAll(makeOwner(), (BitmapIndexedNode) that, 0, bulkChange, ChampSet::updateElement, Objects::equals, ChampSet::keyHash, new ChangeEvent<>()); - if (bulkChange.removed == 0) { - return false; - } - root = newRootNode; - size -= bulkChange.removed; - modCount++; - return true; - } - return super.removeAll(c); - } - - @Override - public boolean retainAll(@NonNull Collection c) { - if (isEmpty()) { - return false; - } - if (c.isEmpty()) { - clear(); - return true; - } - if (c instanceof MutableChampSet m) { - ChampSet that = m.toImmutable(); - BulkChangeEvent bulkChange = new BulkChangeEvent(); - @SuppressWarnings("unchecked") - BitmapIndexedNode newRootNode = root.retainAll(makeOwner(), (BitmapIndexedNode) that, 0, bulkChange, ChampSet::updateElement, Objects::equals, ChampSet::keyHash, new ChangeEvent<>()); - if (bulkChange.removed == 0) { - return false; - } - root = newRootNode; - size -= bulkChange.removed; - modCount++; - return true; - } - return super.retainAll(c); - } - - - @SuppressWarnings("unchecked") - public boolean retainAll(@NonNull Iterable c) { - if (c == this || isEmpty()) { - return false; - } - if ((c instanceof Collection cc && cc.isEmpty()) - || (c instanceof ReadOnlyCollection rc) && rc.isEmpty()) { - clear(); - return true; - } - BulkChangeEvent bulkChange = new BulkChangeEvent(); - BitmapIndexedNode newRootNode; - if (c instanceof ChampSet that) { - newRootNode = root.retainAll(makeOwner(), (BitmapIndexedNode) that, 0, bulkChange, ChampSet::updateElement, Objects::equals, ChampSet::keyHash, new ChangeEvent<>()); - } else if (c instanceof Collection that) { - newRootNode = root.filterAll(makeOwner(), that::contains, 0, bulkChange); - } else if (c instanceof ReadOnlyCollection that) { - newRootNode = root.filterAll(makeOwner(), that::contains, 0, bulkChange); - } else { - HashSet that = new HashSet<>(); - c.forEach(that::add); - newRootNode = root.filterAll(makeOwner(), that::contains, 0, bulkChange); - } - if (bulkChange.removed == 0) { - return false; - } - root = newRootNode; - size -= bulkChange.removed; - modCount++; - return true; - } - - /** - * Removes all elements from this set. - */ - @Override - public void clear() { - root = BitmapIndexedNode.emptyNode(); - size = 0; - modCount++; - } - - /** - * Returns a shallow copy of this set. - */ - @Override - public @NonNull MutableChampSet clone() { - return (MutableChampSet) super.clone(); - } - - @Override - @SuppressWarnings("unchecked") - public boolean contains(@Nullable final Object o) { - return Node.NO_DATA != root.find((E) o, keyHash(o), 0, Objects::equals); - } - - @Override - public @NonNull Iterator iterator() { - return new FailFastIterator<>( - new ChampIterator(root, null), - this::iteratorRemove, this::getModCount - ); - } - - @Override - public Spliterator spliterator() { - return new FailFastSpliterator<>(new ChampSpliterator<>(root, Function.identity(), size, Spliterator.DISTINCT | Spliterator.SIZED), () -> this.modCount); - } - - private void iteratorRemove(E e) { - owner = null; - remove(e); - } - - @Override - @SuppressWarnings("unchecked") - public boolean remove(Object o) { - ChangeEvent details = new ChangeEvent<>(); - root = root.remove(makeOwner(), - (E) o, ChampSet.keyHash(o), 0, details, - Objects::equals); - if (details.isModified()) { - size--; - modCount++; - } - return details.isModified(); - } - - /** - * Returns an immutable copy of this set. - * - * @return an immutable copy - */ - public @NonNull ChampSet toImmutable() { - owner = null; - return size == 0 - ? ChampSet.of() - : root instanceof ChampSet c ? c : new ChampSet<>(root, size); - } - - @Serial - private @NonNull Object writeReplace() { - return new SerializationProxy<>(this); - } - - private static class SerializationProxy extends SetSerializationProxy { - @Serial - private static final long serialVersionUID = 0L; - - protected SerializationProxy(@NonNull Set target) { - super(target); - } - - @Serial - @Override - protected @NonNull Object readResolve() { - return new MutableChampSet<>(deserialized); - } - } -} \ No newline at end of file diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableMapEntry.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableMapEntry.java deleted file mode 100644 index 73af84b4e..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableMapEntry.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * @(#)MutableMapEntry.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; - -import java.io.Serial; -import java.util.AbstractMap; -import java.util.function.BiConsumer; - -/** - * A map entry that supports mutation of the map that contains the entry. - * - * @param the key type - * @param the value type - */ -public class MutableMapEntry extends AbstractMap.SimpleEntry { - @Serial - private static final long serialVersionUID = 0L; - private final @NonNull BiConsumer putFunction; - - public MutableMapEntry(@NonNull BiConsumer putFunction, K key, V value) { - super(key, value); - this.putFunction = putFunction; - } - - @Override - public V setValue(V value) { - V oldValue = super.setValue(value); - putFunction.accept(getKey(), value); - return oldValue; - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorList.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorList.java deleted file mode 100644 index 98e36f601..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorList.java +++ /dev/null @@ -1,317 +0,0 @@ -/* - * @(#)MutableVectorList.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.facade.ListFacade; -import org.jhotdraw8.collection.facade.ReadOnlyListFacade; -import org.jhotdraw8.collection.impl.vector.BitMappedTrie; -import org.jhotdraw8.collection.readonly.ReadOnlyList; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedCollection; -import org.jhotdraw8.collection.readonly.SizeLimitExceededException; -import org.jhotdraw8.collection.sequenced.SequencedCollection; -import org.jhotdraw8.collection.serialization.ListSerializationProxy; - -import java.io.Serial; -import java.io.Serializable; -import java.util.*; -import java.util.stream.Stream; - -/** - * Implements the {@link List} interface using a bit-mapped trie (Vector). - *

- * Features: - *

    - *
  • supports up to {@code Integer.MAX_VALUE} entries
  • - *
  • allows null elements
  • - *
  • is immutable
  • - *
  • is thread-safe
  • - *
  • iterates in the order of the list
  • - *
- *

- * Performance characteristics: - *

    - *
  • addLast: O(log N)
  • - *
  • set: O(log N)
  • - *
  • removeAt: O(N)
  • - *
  • removeFirst,removeLast: O(log N)
  • - *
  • contains: O(N)
  • - *
  • toImmutable: O(1)
  • - *
  • clone: O(1)
  • - *
  • iterator.next(): O(1)
  • - *
- *

- * References: - *

- * This class has been derived from Vavr Vector.java. - *

- *
Vector.java. Copyright 2023 (c) vavr. MIT License.
- *
github.com
- *
- * - * @param the element type - */ -public class MutableVectorList extends AbstractList implements Serializable, ReadOnlyList, SequencedCollection, Cloneable { - @Serial - private static final long serialVersionUID = 0L; - - private @NonNull BitMappedTrie root; - private int size; - - /** - * Constructs a new empty list. - */ - public MutableVectorList() { - root = BitMappedTrie.empty(); - } - - @Override - public void addFirst(E e) { - root = root.prepend(Collections.singleton(e).iterator(), 1); - size++; - modCount++; - } - - @Override - public void addLast(E e) { - root = root.append(e); - size++; - modCount++; - } - - @Override - public @NonNull ReadOnlySequencedCollection readOnlyReversed() { - return new ReadOnlyListFacade<>( - this::size, - index -> get(size - 1 - index), - () -> this - ); - } - - @Override - public @NonNull SequencedCollection _reversed() { - return new ListFacade( - this::size, - index -> get(size - 1 - index), - this::clear, - (index, element) -> add(size - 1 - index, element), - index -> remove(size - 1 - index) - ); - } - - @Override - public int size() { - return size; - } - - @Override - public E get(int index) { - Objects.checkIndex(index, size); - return root.get(index); - } - - @Override - public E getFirst() { - return ReadOnlyList.super.getFirst(); - } - - @Override - public E getLast() { - return ReadOnlyList.super.getLast(); - } - - @Override - public @NonNull ReadOnlyList readOnlySubList(int fromIndex, int toIndex) { - return null; - } - - @Override - public boolean addAll(@NonNull Collection c) { - return addAll(size, c); - } - - @Override - public boolean addAll(int index, Collection c) { - Objects.checkIndex(index, size + 1); - if (size + c.size() > maxSize()) throw new SizeLimitExceededException(); - int oldSize = size; - VectorList immutable = toImmutable().addAll(index, c); - if (oldSize != immutable.size) { - root = immutable; - modCount++; - size = immutable.size; - return true; - } - return false; - } - - - public boolean addAll(int index, @NonNull Iterable c) { - Objects.checkIndex(index, size + 1); - int oldSize = size; - VectorList immutable = toImmutable().addAll(index, c); - if (oldSize != immutable.size) { - root = immutable; - modCount++; - size = immutable.size; - return true; - } - return false; - } - - @Override - public boolean removeAll(@NonNull Collection c) { - int oldSize = size; - @SuppressWarnings("unchecked") - VectorList immutable = toImmutable().removeAll(c); - if (oldSize != immutable.size) { - root = immutable; - modCount++; - size = immutable.size; - return true; - } - return false; - } - - @Override - public boolean retainAll(@NonNull Collection c) { - int oldSize = size; - @SuppressWarnings("unchecked") - VectorList immutable = toImmutable().retainAll(c); - if (oldSize != immutable.size) { - root = immutable; - modCount++; - size = immutable.size; - return true; - } - return false; - } - - /** - * Constructs a list containing the elements in the specified iterable. - * - * @param c an iterable - */ - @SuppressWarnings("unchecked") - public MutableVectorList(@NonNull Iterable c) { - if (c instanceof MutableVectorList) { - c = ((MutableVectorList) c).toImmutable(); - } - if (c instanceof VectorList) { - VectorList that = (VectorList) c; - this.root = that; - this.size = that.size; - } else { - this.root = BitMappedTrie.empty(); - addAll(0, c); - } - } - - @NonNull - public VectorList toImmutable() { - return size == 0 ? VectorList.of() : new VectorList<>(root, size); - } - - @Serial - private @NonNull Object writeReplace() { - return new MutableVectorList.SerializationProxy<>(this); - } - - @Override - public boolean add(E e) { - if (size == maxSize()) throw new SizeLimitExceededException(); - root = root.append(e); - size++; - modCount++; - return true; - - } - - @Override - public E set(int index, E element) { - Objects.checkIndex(index, size); - E oldValue = get(index); - root = root.update(index, element); - - // According to Guava Tests, this method must not affect modCount! - // modCount++; - - return oldValue; - } - - @Override - public void add(int index, E element) { - Objects.checkIndex(index, size + 1); - if (size == maxSize()) throw new SizeLimitExceededException(); - if (index == size) { - add(element); - } else { - addAll(index, Collections.singleton(element)); - } - } - - @Override - public E remove(int index) { - Objects.checkIndex(index, size); - E removed = get(index); - removeRange(index, index + 1); - return removed; - } - - @Override - public @NonNull Spliterator spliterator() { - return root.spliterator(0, size(), Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED); - } - - @Override - public Stream stream() { - return super.stream(); - } - - @Override - protected void removeRange(int fromIndex, int toIndex) { - root = toImmutable().removeRange(fromIndex, toIndex); - size -= toIndex - fromIndex; - modCount++; - } - - @Override - public MutableVectorList clone() { - try { - @SuppressWarnings("unchecked") - MutableVectorList clone = (MutableVectorList) super.clone(); - // TODO: copy mutable state here, so the clone can't change the internals of the original - return clone; - } catch (CloneNotSupportedException e) { - throw new AssertionError(); - } - } - - private static class SerializationProxy extends ListSerializationProxy { - @Serial - private static final long serialVersionUID = 0L; - - protected SerializationProxy(@NonNull List target) { - super(target); - } - - @Serial - @Override - protected @NonNull Object readResolve() { - return new MutableVectorList<>(deserialized); - } - } - - @Override - public E removeFirst() { - return SequencedCollection.super.removeFirst(); - } - - @Override - public E removeLast() { - return SequencedCollection.super.removeLast(); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorMap.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorMap.java deleted file mode 100644 index d373ab740..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorMap.java +++ /dev/null @@ -1,496 +0,0 @@ -/* - * @(#)MutableSequencedChampMap.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.facade.ReadOnlySequencedMapFacade; -import org.jhotdraw8.collection.facade.SequencedMapFacade; -import org.jhotdraw8.collection.facade.SequencedSetFacade; -import org.jhotdraw8.collection.impl.champ.*; -import org.jhotdraw8.collection.iterator.FailFastIterator; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedMap; -import org.jhotdraw8.collection.sequenced.AbstractSequencedMap; -import org.jhotdraw8.collection.sequenced.SequencedCollection; -import org.jhotdraw8.collection.sequenced.SequencedMap; -import org.jhotdraw8.collection.sequenced.SequencedSet; -import org.jhotdraw8.collection.serialization.MapSerializationProxy; - -import java.io.Serial; -import java.util.*; - -/** - * Implements the {@code SequencedMap} interface using a Compressed - * Hash-Array Mapped Prefix-tree (CHAMP) and a bit-mapped trie (Vector). - *

- * Features: - *

    - *
  • supports up to 230 entries
  • - *
  • allows null keys and null values
  • - *
  • is mutable
  • - *
  • is not thread-safe
  • - *
  • iterates in the order, in which keys were inserted
  • - *
- *

- * Performance characteristics: - *

    - *
  • put, putFirst, putLast: O(1) in an amortized sense, because we sometimes have to - * renumber the elements.
  • - *
  • remove: O(1) in an amortized sense, because we sometimes have to renumber the elements.
  • - *
  • containsKey: O(1)
  • - *
  • toImmutable: O(1) + O(log N) distributed across subsequent updates in - * this mutable map
  • - *
  • clone: O(1) + O(log N) distributed across subsequent updates in this - * mutable map and in the clone
  • - *
  • iterator creation: O(1)
  • - *
  • iterator.next: O(1)
  • - *
  • getFirst, getLast: O(1)
  • - *
- *

- * Implementation details: - *

- * See description at {@link VectorMap}. - *

- * References: - *

- *
Michael J. Steindorfer (2017). - * Efficient Immutable Collections.
- *
michael.steindorfer.name - *
The Capsule Hash Trie Collections Library. - *
Copyright (c) Michael Steindorfer. BSD-2-Clause License
- *
github.com - *
- * - * @param the key type - * @param the value type - */ -@SuppressWarnings("exports") -public class MutableVectorMap extends AbstractMutableChampMap> - implements SequencedMap, ReadOnlySequencedMap { - @Serial - private static final long serialVersionUID = 0L; - /** - * Offset of sequence numbers to vector indices. - * - *
vector index = sequence number + offset
- */ - private int offset = 0; - /** - * In this vector we store the elements in the order in which they were inserted. - */ - private @NonNull VectorList vector; - - - /** - * Constructs a new empty map. - */ - public MutableVectorMap() { - root = BitmapIndexedNode.emptyNode(); - vector = VectorList.of(); - } - - /** - * Constructs a map containing the same entries as in the specified - * {@link Map}. - * - * @param c a map - */ - @SuppressWarnings("unchecked") - public MutableVectorMap(@NonNull Map c) { - this((c instanceof MutableVectorMap mvm) - ? ((MutableVectorMap) mvm).toImmutable() - : c.entrySet()); - } - - /** - * Constructs a map containing the same entries as in the specified - * {@link Iterable}. - * - * @param c an iterable - */ - @SuppressWarnings("unchecked") - public MutableVectorMap(@NonNull Iterable> c) { - if (c instanceof VectorMap) { - VectorMap that = (VectorMap) c; - this.root = that; - this.size = that.size; - this.offset = that.offset; - this.vector = that.vector; - } else { - this.root = BitmapIndexedNode.emptyNode(); - this.vector = VectorList.of(); - putAll(c); - } - - } - - - /** - * Removes all entries from this map. - */ - @Override - public void clear() { - root = BitmapIndexedNode.emptyNode(); - vector = VectorList.of(); - size = 0; - modCount++; - offset = -1; - } - - /** - * Returns a shallow copy of this map. - */ - @Override - public @NonNull MutableVectorMap clone() { - return (MutableVectorMap) super.clone(); - } - - @Override - @SuppressWarnings("unchecked") - public boolean containsKey(@Nullable Object o) { - return Node.NO_DATA != root.find(new SequencedEntry<>((K) o), - SequencedEntry.keyHash(o), 0, - SequencedEntry::keyEquals); - } - - @Override - public @NonNull Iterator> iterator() { - return new FailFastIterator<>(Spliterators.iterator(spliterator()), - this::iteratorRemove, () -> modCount); - } - - private @NonNull Iterator> reverseIterator() { - return new FailFastIterator<>(Spliterators.iterator(reverseSpliterator()), - this::iteratorRemove, () -> modCount); - } - - @SuppressWarnings("unchecked") - private @NonNull Spliterator> reverseSpliterator() { - return new ReverseTombSkippingVectorSpliterator>(vector, - e -> new MutableMapEntry<>(this::iteratorPutIfPresent, - ((SequencedEntry) e).getKey(), ((SequencedEntry) e).getValue()), - size(), Spliterator.SIZED | Spliterator.DISTINCT | Spliterator.ORDERED); - } - - @SuppressWarnings("unchecked") - @Override - public @NonNull Spliterator> spliterator() { - return new TombSkippingVectorSpliterator>(vector, - e -> new MutableMapEntry<>(this::iteratorPutIfPresent, - ((SequencedEntry) e).getKey(), ((SequencedEntry) e).getValue()), - 0, size(), Spliterator.SIZED | Spliterator.DISTINCT | Spliterator.ORDERED); - } - - - /** - * Returns a {@link Set} view of the entries contained in this map. - * - * @return a view of the entries contained in this map - */ - @Override - public @NonNull SequencedSet> entrySet() { - return _sequencedEntrySet(); - } - - /** - * Returns a {@link SequencedSet} view of the entries contained in this map. - * - * @return a view of the entries contained in this map - */ - @Override - public @NonNull SequencedSet> _sequencedEntrySet() { - return new SequencedSetFacade<>( - this::iterator, - this::spliterator, - this::reverseIterator, - this::reverseSpliterator, - this::size, - this::containsEntry, - this::clear, - this::removeEntry, - this::firstEntry, - this::lastEntry, null, null, null, null - ); - } - - @SuppressWarnings("unchecked") - @Override - public @Nullable Entry firstEntry() { - return isEmpty() ? null : (SequencedEntry) vector.getFirst(); - } - - /** - * Returns the value to which the specified key is mapped, - * or {@code null} if this map contains no entry for the key. - * - * @param o the key whose associated value is to be returned - * @return the associated value or null - */ - @Override - @SuppressWarnings("unchecked") - public V get(Object o) { - Object result = root.find( - new SequencedEntry<>((K) o), - SequencedEntry.keyHash(o), 0, SequencedEntry::keyEquals); - return (result instanceof SequencedEntry) ? ((SequencedEntry) result).getValue() : null; - } - - - private void iteratorPutIfPresent(@NonNull K k, V v) { - if (containsKey(k)) { - owner = null; - put(k, v); - } - } - - private void iteratorRemove(Entry entry) { - owner = null; - remove(entry.getKey()); - } - - @Override - public long maxSize() { - return 1 << 30; - } - - @Override - public @NonNull SequencedSet _sequencedKeySet() { - return AbstractSequencedMap.createKeySet(this); - } - - @SuppressWarnings("unchecked") - @Override - public @Nullable Entry lastEntry() { - return isEmpty() ? null : (SequencedEntry) vector.getLast(); - } - - @Override - public Entry pollFirstEntry() { - var e = firstEntry(); - if (e == null) return null; - remove(e.getKey()); - return e; - } - - @Override - public Entry pollLastEntry() { - var e = lastEntry(); - if (e == null) return null; - remove(e.getKey()); - return e; - } - - @Override - public V put(K key, V value) { - var oldData = putLast(key, value, false).getOldData(); - return oldData == null ? null : oldData.getValue(); - } - - V putFirstFalse(K key, V value) { - var oldData = putFirst(key, value, false).getOldData(); - return oldData == null ? null : oldData.getValue(); - } - - @Override - public V putFirst(K key, V value) { - var oldData = putFirst(key, value, true).getOldData(); - return oldData == null ? null : oldData.getValue(); - } - - private @NonNull ChangeEvent> putFirst(K key, V val, boolean moveToFirst) { - var details = new ChangeEvent>(); - var newEntry = new SequencedEntry<>(key, val, -offset - 1); - root = root.put(getOrCreateOwner(), newEntry, - SequencedEntry.keyHash(key), 0, details, - moveToFirst ? SequencedEntry::updateAndMoveToFirst : SequencedEntry::update, - SequencedEntry::keyEquals, SequencedEntry::entryKeyHash); - if (details.isReplaced() - && details.getOldDataNonNull().getSequenceNumber() == details.getNewDataNonNull().getSequenceNumber()) { - vector = vector.set(details.getNewDataNonNull().getSequenceNumber() - offset, details.getNewDataNonNull()); - return details; - } - if (details.isModified()) { - if (details.isReplaced()) { - if (moveToFirst) { - var result = SequencedData.vecRemove(vector, details.getOldDataNonNull(), offset); - vector = result.first(); - } - } else { - modCount++; - size++; - } - offset++; - vector = vector.addFirst(newEntry); - renumber(); - } - return details; - } - - @SuppressWarnings("unchecked") - @Override - public boolean putAll(@NonNull Iterable> c) { - if (c instanceof MutableVectorMap that) { - c = (Iterable>) that.toImmutable(); - } - if (isEmpty() && c instanceof VectorMap that) { - if (that.isEmpty()) { - return false; - } - root = (BitmapIndexedNode>) (BitmapIndexedNode) that; - vector = that.vector; - offset = that.offset; - size = that.size; - modCount++; - return true; - } - return super.putAll(c); - } - - @Override - public V putLast(K key, V value) { - var oldData = putLast(key, value, true).getOldData(); - return oldData == null ? null : oldData.getValue(); - } - - @NonNull - ChangeEvent> putLast(final K key, V value, boolean moveToLast) { - var details = new ChangeEvent>(); - var newEntry = new SequencedEntry<>(key, value, vector.size() - offset); - root = root.put(getOrCreateOwner(), newEntry, - SequencedEntry.keyHash(key), 0, details, - moveToLast ? SequencedEntry::updateAndMoveToLast : SequencedEntry::update, - SequencedEntry::keyEquals, SequencedEntry::entryKeyHash); - if (details.isReplaced() - && details.getOldDataNonNull().getSequenceNumber() == details.getNewDataNonNull().getSequenceNumber()) { - vector = vector.set(details.getNewDataNonNull().getSequenceNumber() - offset, details.getNewDataNonNull()); - return details; - } - if (details.isModified()) { - if (details.isReplaced()) { - var result = SequencedData.vecRemove(vector, details.getOldDataNonNull(), offset); - vector = result.first(); - offset = result.second(); - } else { - size++; - } - modCount++; - vector = vector.add(newEntry); - renumber(); - } - return details; - } - - @Override - public @NonNull ReadOnlySequencedMap readOnlyReversed() { - return new ReadOnlySequencedMapFacade<>( - this::iterator, - this::reverseIterator, - this::size, - this::containsKey, - this::get, - this::lastEntry, - this::firstEntry - ); - } - - @Override - public V remove(Object o) { - @SuppressWarnings("unchecked") final K key = (K) o; - ChangeEvent> details = removeAndGiveDetails(key); - if (details.isModified()) { - return details.getOldData().getValue(); - } - return null; - } - - @NonNull - ChangeEvent> removeAndGiveDetails(K key) { - var details = new ChangeEvent>(); - root = root.remove(getOrCreateOwner(), - new SequencedEntry<>(key), - SequencedEntry.keyHash(key), 0, details, SequencedEntry::keyEquals); - if (details.isModified()) { - var oldElem = details.getOldDataNonNull(); - var result = SequencedData.vecRemove(vector, oldElem, offset); - vector = result.first(); - offset = result.second(); - size--; - modCount++; - renumber(); - } - return details; - } - - /** - * Renumbers the sequence numbers if they have overflown, - * or if the extent of the sequence numbers is more than - * 4 times the size of the set. - */ - private void renumber() { - if (SequencedData.vecMustRenumber(size, offset, vector.size())) { - var result = SequencedData.vecRenumber(getOrCreateOwner(), size, root, vector, - SequencedEntry::entryKeyHash, SequencedEntry::keyEquals, - (e, seq) -> new SequencedEntry<>(e.getKey(), e.getValue(), seq)); - root = result.first(); - vector = result.second(); - offset = 0; - } - } - - @Override - public @NonNull SequencedMap _reversed() { - return new SequencedMapFacade<>( - this::reverseIterator, - this::iterator, - this::size, - this::containsKey, - this::get, - this::clear, - this::remove, - this::lastEntry, - this::firstEntry, - this::putFirstFalse, - this::putLast, - this::putFirst - ); - } - - /** - * Returns an immutable copy of this map. - * - * @return an immutable copy - */ - public @NonNull VectorMap toImmutable() { - owner = null; - return size == 0 ? VectorMap.of() - : root instanceof VectorMap m ? m : new VectorMap<>(root, vector, size, offset); - } - - @Override - public @NonNull SequencedCollection _sequencedValues() { - return AbstractSequencedMap.createValues(this); - } - - @Serial - private @NonNull Object writeReplace() { - return new SerializationProxy<>(this); - } - - private static class SerializationProxy extends MapSerializationProxy { - @Serial - private static final long serialVersionUID = 0L; - - protected SerializationProxy(Map target) { - super(target); - } - - @Serial - @Override - protected @NonNull Object readResolve() { - return new MutableVectorMap<>(deserialized); - } - } -} \ No newline at end of file diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorSet.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorSet.java deleted file mode 100644 index e74789029..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorSet.java +++ /dev/null @@ -1,439 +0,0 @@ -/* - * @(#)MutableVectorSet.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.facade.ReadOnlySequencedSetFacade; -import org.jhotdraw8.collection.facade.SequencedSetFacade; -import org.jhotdraw8.collection.impl.champ.*; -import org.jhotdraw8.collection.iterator.FailFastIterator; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedSet; -import org.jhotdraw8.collection.sequenced.SequencedSet; -import org.jhotdraw8.collection.serialization.SetSerializationProxy; -import org.jhotdraw8.collection.spliterator.FailFastSpliterator; - -import java.io.Serial; -import java.util.*; - -import static org.jhotdraw8.collection.impl.champ.SequencedData.vecRemove; - -/** - * Implements the {@code SequencedSet} interface using a Compressed - * Hash-Array Mapped Prefix-tree (CHAMP) and a bit-mapped trie (Vector). - *

- * Features: - *

    - *
  • supports up to 230 elements
  • - *
  • allows null elements
  • - *
  • is mutable
  • - *
  • is not thread-safe
  • - *
  • iterates in the order, in which elements were inserted
  • - *
- *

- * Performance characteristics: - *

    - *
  • add: O(1) amortized
  • - *
  • remove: O(1)
  • - *
  • contains: O(1)
  • - *
  • toImmutable: O(1) + O(log N) distributed across subsequent updates in - * this set
  • - *
  • clone: O(1) + O(log N) distributed across subsequent updates in this - * set and in the clone
  • - *
  • iterator creation: O(1)
  • - *
  • iterator.next: O(1)
  • - *
  • getFirst, getLast: O(1)
  • - *
- *

- * Implementation details: - *

- * See description at {@link VectorSet}. - *

- * References: - *

- *
Michael J. Steindorfer (2017). - * Efficient Immutable Collections.
- *
michael.steindorfer.name - * - *
The Capsule Hash Trie Collections Library. - *
Copyright (c) Michael Steindorfer. BSD-2-Clause License
- *
github.com - *
- * - * @param the element type - */ -@SuppressWarnings("exports") -public class MutableVectorSet extends AbstractMutableChampSet> implements ReadOnlySequencedSet, - SequencedSet { - @Serial - private static final long serialVersionUID = 0L; - - /** - * Offset of sequence numbers to vector indices. - * - *
vector index = sequence number + offset
- */ - private int offset = 0; - /** - * In this vector we store the elements in the order in which they were inserted. - */ - private @NonNull VectorList vector; - - /** - * Constructs a new empty set. - */ - public MutableVectorSet() { - root = BitmapIndexedNode.emptyNode(); - vector = VectorList.of(); - } - - /** - * Constructs a set containing the elements in the specified - * {@link Iterable}. - * - * @param c an iterable - */ - @SuppressWarnings("unchecked") - public MutableVectorSet(Iterable c) { - if (c instanceof MutableVectorSet) { - c = ((MutableVectorSet) c).toImmutable(); - } - if (c instanceof VectorSet) { - VectorSet that = (VectorSet) c; - this.root = that; - this.size = that.size; - this.offset = that.offset; - this.vector = that.vector; - } else { - this.root = BitmapIndexedNode.emptyNode(); - this.vector = VectorList.of(); - addAll(c); - } - } - - @Override - public boolean add(@Nullable E e) { - return addLast(e, false); - } - - @Override - public void addFirst(@Nullable E e) { - addFirst(e, true); - } - - private boolean addFirst(@Nullable E e, boolean moveToFirst) { - var details = new ChangeEvent>(); - var newElem = new SequencedElement<>(e, -offset - 1); - root = root.put(makeOwner(), newElem, - SequencedElement.keyHash(e), 0, details, - moveToFirst ? SequencedElement::putAndMoveToFirst : SequencedElement::put, - Objects::equals, SequencedElement::elementKeyHash); - boolean modified = details.isModified(); - if (modified) { - if (details.isReplaced()) { - if (moveToFirst) { - var result = vecRemove(vector, details.getOldDataNonNull(), offset); - vector = result.first(); - } - } else { - size++; - } - offset++; - modCount++; - vector = vector.addFirst(newElem); - renumber(); - } - return modified; - } - - @Override - public void addLast(@Nullable E e) { - addLast(e, true); - } - - private boolean addLast(@Nullable E e, boolean moveToLast) { - var details = new ChangeEvent>(); - var newElem = new SequencedElement<>(e, offset + vector.size()); - root = root.put(makeOwner(), - newElem, SequencedElement.keyHash(e), 0, - details, - moveToLast ? SequencedElement::putAndMoveToLast : SequencedElement::put, - Objects::equals, SequencedElement::elementKeyHash); - boolean modified = details.isModified(); - if (modified) { - var oldElem = details.getOldData(); - if (details.isReplaced()) { - var result = vecRemove(vector, oldElem, offset); - vector = result.first(); - offset = result.second(); - } else { - modCount++; - size++; - } - vector = vector.add(newElem); - renumber(); - } - return modified; - } - - /** - * Removes all elements from this set. - */ - @Override - public void clear() { - root = BitmapIndexedNode.emptyNode(); - vector = VectorList.of(); - size = 0; - modCount++; - offset = -1; - } - - /** - * Returns a shallow copy of this set. - */ - @Override - public @NonNull MutableVectorSet clone() { - return (MutableVectorSet) super.clone(); - } - - @Override - @SuppressWarnings("unchecked") - public boolean contains(@Nullable final Object o) { - return Node.NO_DATA != root.find(new SequencedElement<>((E) o), - SequencedElement.keyHash(o), 0, Objects::equals); - } - - @SuppressWarnings("unchecked") - @Override - public E getFirst() { - return ((SequencedElement) vector.getFirst()).getElement(); - } - - @SuppressWarnings("unchecked") - @Override - public E getLast() { - return ((SequencedElement) vector.getLast()).getElement(); - } - - - @Override - @SuppressWarnings("unchecked") - public @NonNull Iterator iterator() { - return new FailFastIterator<>(Spliterators.iterator(new TombSkippingVectorSpliterator<>(vector, - (Object o) -> ((SequencedElement) o).getElement(), - 0, size(), Spliterator.SIZED | Spliterator.DISTINCT | Spliterator.ORDERED)), - this::iteratorRemove, () -> modCount); - } -/* - public boolean removeAll(@NonNull Iterable c) { - if (isEmpty() - || (c instanceof Collection cc && cc.isEmpty()) - || (c instanceof ReadOnlyCollection rc) && rc.isEmpty()) { - return false; - } - if (c == this) { - clear(); - return true; - } - Predicate predicate; - if (c instanceof Collection that) { - predicate = that::contains; - } else if (c instanceof ReadOnlyCollection that) { - predicate = that::contains; - } else { - HashSet that = new HashSet<>(); - c.forEach(that::add); - predicate = that::contains; - } - return filterAll(predicate.negate()); - } -/* - public boolean retainAll(@NonNull Iterable c) { - if(c==this||isEmpty()) { - return false; - } - if ((c instanceof Collection cc && cc.isEmpty()) - || (c instanceof ReadOnlyCollection rc) && rc.isEmpty()) { - clear(); - return true; - } - Predicate predicate; - if (c instanceof Collection that) { - predicate = that::contains; - } else if (c instanceof ReadOnlyCollection that) { - predicate = that::contains; - } else { - HashSet that = new HashSet<>(); - c.forEach(that::add); - predicate = that::contains; - } - return filterAll(predicate); - } - boolean filterAll(@NonNull Predicate predicate) { - class VectorPredicate implements Predicate> { - VectorList newVector = vector; - int newOffset = offset; - - @Override - public boolean test(SequencedElement e) { - if (!predicate.test(e.getElement())) { - OrderedPair, Integer> result = vecRemove(newVector, e, newOffset); - newVector = result.first(); - newOffset = result.second(); - return false; - } - return true; - } - } - VectorPredicate vp = new VectorPredicate(); - BulkChangeEvent bulkChange = new BulkChangeEvent(); - BitmapIndexedNode> newRootNode = root.filterAll(makeOwner(), vp, 0, bulkChange); - if (bulkChange.removed == 0) { - return false; - } - root = newRootNode; - vector = vp.newVector; - offset = vp.newOffset; - size -= bulkChange.removed; - modCount++; - return true; - } -*/ - - @Override - public long maxSize() { - return 1 << 30; - } - - @SuppressWarnings("unchecked") - private @NonNull Iterator reverseIterator() { - return new FailFastIterator<>(Spliterators.iterator(new ReverseTombSkippingVectorSpliterator<>(vector, - (Object o) -> ((SequencedElement) o).getElement(), - size(), Spliterator.SIZED | Spliterator.DISTINCT | Spliterator.ORDERED)), - this::iteratorRemove, () -> modCount); - } - - @SuppressWarnings("unchecked") - private @NonNull Spliterator reverseSpliterator() { - return new FailFastSpliterator<>(new ReverseTombSkippingVectorSpliterator<>(vector, - (Object o) -> ((SequencedElement) o).getElement(), - size(), Spliterator.SIZED | Spliterator.DISTINCT | Spliterator.ORDERED), () -> modCount); - } - - @SuppressWarnings("unchecked") - @Override - public @NonNull Spliterator spliterator() { - return new FailFastSpliterator<>(new TombSkippingVectorSpliterator<>(vector, - (Object o) -> ((SequencedElement) o).getElement(), - 0, size(), Spliterator.SIZED | Spliterator.DISTINCT | Spliterator.ORDERED), () -> modCount); - } - - private void iteratorRemove(E element) { - owner = null; - remove(element); - } - - @Override - public @NonNull ReadOnlySequencedSet readOnlyReversed() { - return new ReadOnlySequencedSetFacade<>(this._reversed()); - } - - @SuppressWarnings("unchecked") - @Override - public boolean remove(Object o) { - var details = new ChangeEvent>(); - root = root.remove(makeOwner(), - new SequencedElement<>((E) o), - SequencedElement.keyHash(o), 0, details, Objects::equals); - boolean modified = details.isModified(); - if (modified) { - var result = vecRemove(vector, details.getOldDataNonNull(), offset); - size--; - modCount++; - vector = result.first(); - offset = result.second(); - renumber(); - } - return modified; - } - - @Override - public E removeFirst() { - var e = this.getFirst(); - remove(e); - return e; - } - - @Override - public E removeLast() { - var e = this.getLast(); - remove(e); - return e; - } - - /** - * Renumbers the sequence numbers if they have overflown. - */ - private void renumber() { - if (SequencedData.vecMustRenumber(size, offset, vector.size())) { - var result = SequencedData.vecRenumber(makeOwner(), size, root, vector, - SequencedElement::elementKeyHash, Objects::equals, - (e, seq) -> new SequencedElement<>(e.getElement(), seq)); - root = result.first(); - vector = result.second(); - offset = 0; - } - } - - @Override - public @NonNull SequencedSet _reversed() { - return new SequencedSetFacade<>( - this::reverseIterator, - this::reverseSpliterator, - this::iterator, - this::spliterator, - this::size, - this::contains, - this::clear, - this::remove, - this::getLast, this::getFirst, - e -> addFirst(e, false), this::add, - this::addLast, this::addFirst - ); - } - - /** - * Returns an immutable copy of this set. - * - * @return an immutable copy - */ - public @NonNull VectorSet toImmutable() { - owner = null; - return size == 0 - ? VectorSet.of() - : root instanceof VectorSet c ? c : new VectorSet<>(root, vector, size, offset); - } - - @Serial - private @NonNull Object writeReplace() { - return new SerializationProxy<>(this); - } - - private static class SerializationProxy extends SetSerializationProxy { - @Serial - private static final long serialVersionUID = 0L; - - protected SerializationProxy(Set target) { - super(target); - } - - @Serial - @Override - protected @NonNull Object readResolve() { - return new MutableVectorSet<>(deserialized); - } - } -} \ No newline at end of file diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorList.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorList.java deleted file mode 100644 index 139c99f9b..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorList.java +++ /dev/null @@ -1,382 +0,0 @@ -/* - * @(#)VectorList.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.facade.ReadOnlyListFacade; -import org.jhotdraw8.collection.immutable.ImmutableList; -import org.jhotdraw8.collection.impl.vector.BitMappedTrie; -import org.jhotdraw8.collection.readonly.ReadOnlyCollection; -import org.jhotdraw8.collection.readonly.ReadOnlyList; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedCollection; -import org.jhotdraw8.collection.serialization.ListSerializationProxy; -import org.jhotdraw8.collection.transform.Transformer; - -import java.io.Serial; -import java.io.Serializable; -import java.util.*; -import java.util.function.Function; - -import static org.jhotdraw8.collection.impl.vector.ArrayType.obj; - -/** - * Implements the {@link ImmutableList} interface using a bit-mapped trie - * (Vector). - *

- * The code has been derived from Vavr Vector.java. - *

- * Features: - *

    - *
  • supports up to {@code Integer.MAX_VALUE} entries
  • - *
  • allows null elements
  • - *
  • is immutable
  • - *
  • is thread-safe
  • - *
  • iterates in the order of the list
  • - *
- *

- * Performance characteristics: - *

    - *
  • addLast: O(log N)
  • - *
  • set: O(log N)
  • - *
  • removeAt: O(N)
  • - *
  • removeFirst,removeLast: O(log N)
  • - *
  • contains: O(N)
  • - *
  • toMutable: O(1)
  • - *
  • clone: O(1)
  • - *
  • iterator.next(): O(log N)
  • - *
  • getFirst, getLast: O(log N)
  • - *
  • reversed: O(N)
  • - *
- *

- * References: - *

- * For a similar design, see 'Vector.java' in vavr. Note, that this code is not a derivative - * of that code. - *

- *
Vector.java. Copyright 2023 (c) vavr. MIT License.
- *
github.com
- *
- * - * @param the element type - */ -public class VectorList extends BitMappedTrie implements ImmutableList, Serializable { - - final int size; - - /** - * Constructs a new empty list. - */ - private VectorList() { - super(obj(), obj().empty(), 0, 0, 0); - size = 0; - } - - VectorList(BitMappedTrie root, int size) { - super(root.type, root.array, root.offset, root.length, root.depthShift); - this.size = size; - } - - - private static final VectorList EMPTY = new VectorList<>(); - - @SuppressWarnings("unchecked") - public static VectorList of() { - return (VectorList) EMPTY; - } - - @SafeVarargs - public static VectorList of(T... t) { - return new VectorList<>(BitMappedTrie.ofAll(t), t.length); - - } - - @SuppressWarnings("unchecked") - public static VectorList copyOf(Iterable iterable) { - Objects.requireNonNull(iterable, "iterable is null"); - if (iterable instanceof Collection c && c.isEmpty() - || iterable instanceof ReadOnlyCollection rc && rc.isEmpty()) { - return of(); - } - if (iterable instanceof VectorList) { - return (VectorList) iterable; - } - if (iterable instanceof MutableVectorList mc) { - return (VectorList) mc.toImmutable(); - } - if (iterable instanceof Collection c) { - return new VectorList<>(BitMappedTrie.ofAll(c.toArray()), c.size()); - } - BitMappedTrie root = BitMappedTrie.empty().appendAll(iterable); - return root.length() == 0 ? of() : new VectorList<>(root, root.length); - } - - @Override - public @NonNull VectorList clear() { - return isEmpty() ? this : of(); - } - - @Override - public @NonNull VectorList add(@NonNull E element) { - return new VectorList<>(append(element), size + 1); - } - - @Override - public @NonNull VectorList add(int index, @NonNull E element) { - if (index == 0) { - return new VectorList<>(prepend(element), size + 1); - } - return index == size ? add(element) : addAll(index, Collections.singleton(element)); - } - - @Override - public @NonNull VectorList addAll(@NonNull Iterable c) { - Objects.requireNonNull(c, "iterable is null"); - if (isEmpty()) { - return copyOf(c); - } - int cSize = c instanceof Collection cc ? cc.size() : - c instanceof ReadOnlyCollection rcc ? rcc.size() : -1; - if (cSize == 0) { - return this; - } - if (cSize < 0) { - BitMappedTrie root = this; - int newSize = size; - for (E e : c) { - root = root.append(e); - newSize++; - } - return new VectorList<>(root, newSize); - } - return new VectorList<>(appendAll(c), size + cSize); - } - - @Override - public @NonNull VectorList addFirst(@Nullable E element) { - return add(0, element); - } - - @Override - public @NonNull VectorList addLast(@Nullable E element) { - return new VectorList<>(append(element), size + 1); - } - - @Override - public @NonNull VectorList addAll(int index, @NonNull Iterable c) { - Objects.requireNonNull(c, "c is null"); - if (index >= 0 && index <= size) { - final VectorList begin = readOnlySubList(0, index).addAll(c); - final VectorList end = readOnlySubList(index, size); - return begin.addAll(end); - } else { - throw new IndexOutOfBoundsException("addAll(" + index + ", c) on Vector of size " + size); - } - } - - @Override - public long maxSize() { - return Integer.MAX_VALUE - 8; - } - - @Override - public @NonNull ReadOnlySequencedCollection readOnlyReversed() { - return new ReadOnlyListFacade<>( - () -> size, - index -> get(size - 1 - index), - () -> this); - } - - public @NonNull VectorList reversed() { - return size < 2 ? this : VectorList.copyOf(readOnlyReversed()); - } - - @Override - public @NonNull VectorList remove(@NonNull E element) { - int index = indexOf(element); - return index < 0 ? this : removeAt(index); - } - - @Override - public @NonNull VectorList removeAt(int index) { - return removeRange(index, index + 1); - } - - @Override - public VectorList removeFirst() { - return (VectorList) ImmutableList.super.removeFirst(); - } - - @Override - public VectorList removeLast() { - return (VectorList) ImmutableList.super.removeLast(); - } - - @SuppressWarnings("unchecked") - @Override - public @NonNull VectorList retainAll(@NonNull Iterable c) { - if (isEmpty()) { - return this; - } - final Collection set; - if (c instanceof Collection cc) { - set = (Collection) cc; - } else if (c instanceof ReadOnlyCollection rc) { - set = (Collection) rc.asCollection(); - } else { - set = new HashSet<>(); - c.forEach(e -> set.add((E) e)); - } - if (set.isEmpty()) return of(); - var t = this.toMutable(); - boolean modified = false; - for (E key : this) { - if (!set.contains(key)) { - t.remove(key); - modified = true; - } - } - return modified ? t.toImmutable() : this; - } - - @Override - public @NonNull VectorList removeRange(int fromIndex, int toIndex) { - Objects.checkIndex(fromIndex, toIndex + 1); - Objects.checkIndex(toIndex, size + 1); - var begin = take(fromIndex); - var end = drop(toIndex); - return new VectorList<>(begin.length > end.length - ? begin.append(end.iterator(), end.length) - : end.prepend(begin.iterator(), begin.length), - size - (toIndex - fromIndex)); - } - - @Override - public @NonNull VectorList removeAll(@NonNull Iterable c) { - if (isEmpty()) return this; - VectorList result = this; - Outer: - for (Object e : c) { - for (int index = result.indexOf(e); index >= 0; index = result.indexOf(e, index)) { - result = result.removeAt(index); - if (result.isEmpty()) { - break Outer; - } - } - } - return result; - } - - @Override - public @NonNull VectorList set(int index, @NonNull E element) { - BitMappedTrie root = update(index, element); - return root == this ? this : new VectorList<>(root, size); - } - - @Override - public E get(int index) { - return super.get(index); - } - - @Override - public @NonNull VectorList readOnlySubList(int fromIndex, int toIndex) { - Objects.checkIndex(fromIndex, toIndex + 1); - Objects.checkIndex(toIndex, size + 1); - BitMappedTrie root = this; - if (toIndex < size) { - root = root.take(toIndex); - } - if (fromIndex > 0) { - root = root.drop(fromIndex); - } - return root == this ? this : new VectorList<>(root, toIndex - fromIndex); - } - - @Override - public int size() { - return size; - } - - public int indexOf(Object o, int fromIndex) { - if (fromIndex < size) { - for (Iterator i = iterator(fromIndex, size()); i.hasNext(); fromIndex++) { - E e = i.next(); - if (Objects.equals(o, e)) { - return fromIndex; - } - } - } - return -1; - } - - @Override - public boolean contains(Object o) { - for (E e : this) { - if (Objects.equals(e, o)) return true; - } - return false; - } - - @Override - public @NonNull MutableVectorList toMutable() { - return new MutableVectorList<>(this); - } - - @Override - public @NonNull Iterator iterator() { - return super.iterator(0, size()); - } - - @Override - public @NonNull Spliterator spliterator() { - return super.spliterator(0, size(), Spliterator.SIZED | Spliterator.ORDERED | Spliterator.SUBSIZED); - } - - @Override - public int hashCode() { - return ReadOnlyList.iteratorToHashCode(iterator()); - } - - @Override - public boolean equals(Object obj) { - return ReadOnlyList.listEquals(this, obj); - } - - @Override - public Transformer> transformed() { - return this::transform; - } - - private R transform(Function, ? extends R> f) { - return f.apply(this); - } - - @Override - public String toString() { - return ReadOnlyCollection.iterableToString(this); - } - - @Serial - private @NonNull Object writeReplace() { - return new VectorList.SerializationProxy<>(this.toMutable()); - } - - private static class SerializationProxy extends ListSerializationProxy { - @Serial - private static final long serialVersionUID = 0L; - - protected SerializationProxy(@NonNull List target) { - super(target); - } - - @Serial - @Override - protected @NonNull Object readResolve() { - return VectorList.of().addAll(deserialized); - } - } - -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorMap.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorMap.java deleted file mode 100644 index e5e6fece7..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorMap.java +++ /dev/null @@ -1,474 +0,0 @@ -/* - * @(#)SequencedChampMap.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.facade.ReadOnlySequencedMapFacade; -import org.jhotdraw8.collection.immutable.ImmutableSequencedMap; -import org.jhotdraw8.collection.impl.IdentityObject; -import org.jhotdraw8.collection.impl.champ.*; -import org.jhotdraw8.collection.readonly.ReadOnlyMap; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedMap; -import org.jhotdraw8.collection.serialization.MapSerializationProxy; -import org.jhotdraw8.collection.transform.Transformer; - -import java.io.ObjectStreamException; -import java.io.Serial; -import java.io.Serializable; -import java.util.*; -import java.util.function.Function; - -/** - * Implements the {@link ImmutableSequencedMap} interface using a Compressed - * Hash-Array Mapped Prefix-tree (CHAMP) and a bit-mapped trie (Vector). - *

- * Features: - *

    - *
  • supports up to 230 entries
  • - *
  • allows null keys and null values
  • - *
  • is immutable
  • - *
  • is thread-safe
  • - *
  • iterates in the order, in which keys were inserted
  • - *
- *

- * Performance characteristics: - *

    - *
  • put, putFirst, putLast: O(log N) in an amortized sense, because we sometimes have to - * renumber the elements.
  • - *
  • remove: O(log N) in an amortized sense, because we sometimes have to renumber the elements.
  • - *
  • containsKey: O(1)
  • - *
  • toMutable: O(1) + O(log N) distributed across subsequent updates in - * the mutable copy
  • - *
  • clone: O(1)
  • - *
  • iterator creation: O(1)
  • - *
  • iterator.next: O(log N)
  • - *
  • getFirst, getLast: O(log N)
  • - *
- *

- * Implementation details: - *

- * This map performs read and write operations of single elements in O(log N) time, - * and in O(log N) space, where N is the number of elements in the set. - *

- * Uses a Compressed Hash-Array Mapped Prefix-tree (CHAMP) trie for storing - * the map entries. - *

- * The CHAMP trie contains nodes that may be shared with other maps. - *

- * If a write operation is performed on a node, then this set creates a - * copy of the node and of all parent nodes up to the root (copy-path-on-write). - * Since the CHAMP trie has a fixed maximal height, the cost is O(1). - *

- * This map can create a mutable copy of itself in O(1) time and O(1) space - * using method {@link #toMutable()}. The mutable copy shares its nodes - * with this map, until it has gradually replaced the nodes with exclusively - * owned nodes. - *

- * Insertion Order: - *

- * This map uses a counter to keep track of the insertion order. - * It stores the current value of the counter in the sequence number - * field of each data entry. If the counter wraps around, it must renumber all - * sequence numbers. - *

- * The renumbering is why the {@code add} and {@code remove} methods are O(1) - * only in an amortized sense. - *

- * To support iteration, we use a Vector. The Vector has the same contents - * as the CHAMP trie. However, its elements are stored in insertion order. - *

- * If an element is removed from the CHAMP trie that is not the first or the - * last element of the Vector, we replace its corresponding element in - * the Vector by a tombstone. If the element is at the start or end of the Vector, - * we remove the element and all its neighboring tombstones from the Vector. - *

- * A tombstone can store the number of neighboring tombstones in ascending and in descending - * direction. We use these numbers to skip tombstones when we iterate over the vector. - * Since we only allow iteration in ascending or descending order from one of the ends of - * the vector, we do not need to keep the number of neighbors in all tombstones up to date. - * It is sufficient, if we update the neighbor with the lowest index and the one with the - * highest index. - *

- * If the number of tombstones exceeds half of the size of the collection, we renumber all - * sequence numbers, and we create a new Vector. - *

- * The immutable version of this set extends from the non-public class - * {@code ChampBitmapIndexNode}. This design safes 16 bytes for every instance, - * and reduces the number of redirections for finding an element in the - * collection by 1. - *

- * References: - *

- * For a similar design, see 'VectorMap.scala'. Note, that this code is not a derivative - * of that code. - *

- *
The Scala library. VectorMap.scala. Copyright EPFL and Lightbend, Inc. Apache License 2.0.
- *
github.com - *
- *
- * - * @param the key type - * @param the value type - */ -@SuppressWarnings("exports") -public class VectorMap extends BitmapIndexedNode> implements ImmutableSequencedMap, Serializable { - private static final @NonNull VectorMap EMPTY = new VectorMap<>( - BitmapIndexedNode.emptyNode(), VectorList.of(), 0, 0); - @Serial - private static final long serialVersionUID = 0L; - /** - * Offset of sequence numbers to vector indices. - * - *
vector index = sequence number + offset
- */ - final int offset; - /** - * The size of the map. - */ - final int size; - /** - * In this vector we store the elements in the order in which they were inserted. - */ - final @NonNull VectorList vector; - - VectorMap(@NonNull BitmapIndexedNode> root, - @NonNull VectorList vector, - int size, int offset) { - super(root.nodeMap(), root.dataMap(), root.mixed); - this.size = size; - this.offset = offset; - this.vector = Objects.requireNonNull(vector); - } - - /** - * Returns an immutable copy of the provided map. - * - * @param map a map - * @param the key type - * @param the value type - * @return an immutable copy - */ - public static @NonNull VectorMap copyOf(@NonNull Iterable> map) { - return VectorMap.of().putAll(map); - } - - /** - * Returns an immutable copy of the provided map. - * - * @param map a map - * @param the key type - * @param the value type - * @return an immutable copy - */ - public static @NonNull VectorMap copyOf(@NonNull Map map) { - return VectorMap.of().putAll(map); - } - - /** - * Returns an empty immutable map. - * - * @param the key type - * @param the value type - * @return an empty immutable map - */ - @SuppressWarnings("unchecked") - public static @NonNull VectorMap of() { - return (VectorMap) VectorMap.EMPTY; - } - - - /** - * {@inheritDoc} - */ - @Override - public @NonNull VectorMap clear() { - return isEmpty() ? this : of(); - } - - @Override - public boolean containsKey(@Nullable Object o) { - @SuppressWarnings("unchecked") final K key = (K) o; - return find(new SequencedEntry<>(key), SequencedEntry.keyHash(key), 0, - SequencedEntry::keyEquals) != Node.NO_DATA; - } - - @Override - public boolean equals(@Nullable Object other) { - if (other == this) { - return true; - } - if (other instanceof VectorMap) { - VectorMap that = (VectorMap) other; - return size == that.size && equivalent(that); - } else { - return ReadOnlyMap.mapEquals(this, other); - } - } - - @SuppressWarnings("unchecked") - public Map.@Nullable Entry firstEntry() { - return isEmpty() ? null : (Map.Entry) vector.getFirst(); - } - - @SuppressWarnings("unchecked") - public Map.@Nullable Entry lastEntry() { - return isEmpty() ? null : (Map.Entry) vector.getLast(); - } - - @Override - @SuppressWarnings("unchecked") - public V get(Object o) { - Object result = find( - new SequencedEntry<>((K) o), - SequencedEntry.keyHash(o), 0, SequencedEntry::keyEquals); - return (V) ((result instanceof SequencedEntry entry) ? entry.getValue() : null); - } - - @Override - public int hashCode() { - return ReadOnlyMap.iteratorToHashCode(iterator()); - } - - @Override - public boolean isEmpty() { - return size == 0; - } - - @Override - public @NonNull Iterator> iterator() { - return Spliterators.iterator(spliterator()); - } - - @Override - public long maxSize() { - return 1 << 30; - } - - @Override - public @NonNull VectorMap put(@NonNull K key, @Nullable V value) { - return putLast(key, value, false); - } - - @Override - public @NonNull VectorMap putAll(@NonNull Map m) { - return (VectorMap) ImmutableSequencedMap.super.putAll(m); - } - - @Override - public @NonNull VectorMap putAll(@NonNull Iterable> c) { - var m = toMutable(); - m.putAll(c); - return m.toImmutable(); - } - - @NonNull - private VectorMap putFirst(@NonNull K key, @Nullable V value, boolean moveToFirst) { - var details = new ChangeEvent>(); - var newEntry = new SequencedEntry<>(key, value, -offset - 1); - var newRoot = put(null, newEntry, - SequencedEntry.keyHash(key), 0, details, - moveToFirst ? SequencedEntry::updateAndMoveToFirst : SequencedEntry::update, - SequencedEntry::keyEquals, SequencedEntry::entryKeyHash); - if (details.isReplaced() - && details.getOldDataNonNull().getSequenceNumber() == details.getNewDataNonNull().getSequenceNumber()) { - var newVector = vector.set(details.getNewDataNonNull().getSequenceNumber() - offset, details.getNewDataNonNull()); - return new VectorMap<>(newRoot, newVector, size, offset); - } - if (details.isModified()) { - var newVector = vector; - int newSize = size; - - if (details.isReplaced()) { - if (moveToFirst) { - var result = SequencedData.vecRemove(newVector, details.getOldDataNonNull(), offset); - newVector = result.first(); - } - } else { - newSize++; - } - int newOffset = offset + 1; - newVector = newVector.addFirst(newEntry); - return renumber(newRoot, newVector, newSize, newOffset); - } - return this; - } - - @Override - public @NonNull VectorMap putFirst(@NonNull K key, @Nullable V value) { - return putFirst(key, value, true); - } - - @NonNull - private VectorMap putLast(@NonNull K key, @Nullable V value, boolean moveToLast) { - var details = new ChangeEvent>(); - var newEntry = new SequencedEntry<>(key, value, vector.size() - offset); - var newRoot = put(null, newEntry, - SequencedEntry.keyHash(key), 0, details, - moveToLast ? SequencedEntry::updateAndMoveToLast : SequencedEntry::update, - SequencedEntry::keyEquals, SequencedEntry::entryKeyHash); - if (details.isReplaced() - && details.getOldDataNonNull().getSequenceNumber() == details.getNewDataNonNull().getSequenceNumber()) { - var newVector = vector.set(details.getNewDataNonNull().getSequenceNumber() - offset, details.getNewDataNonNull()); - return new VectorMap<>(newRoot, newVector, size, offset); - } - if (details.isModified()) { - var newVector = vector; - int newOffset = offset; - int newSize = size; - if (details.isReplaced()) { - if (moveToLast) { - var oldElem = details.getOldDataNonNull(); - var result = SequencedData.vecRemove(newVector, oldElem, newOffset); - newVector = result.first(); - newOffset = result.second(); - } - } else { - newSize++; - } - newVector = newVector.addLast(newEntry); - return renumber(newRoot, newVector, newSize, newOffset); - } - return this; - } - - @Override - public @NonNull VectorMap putLast(@NonNull K key, @Nullable V value) { - return putLast(key, value, true); - } - - @Override - public @NonNull ReadOnlySequencedMap readOnlyReversed() { - return new ReadOnlySequencedMapFacade<>( - this::reverseIterator, - this::iterator, - this::size, - this::containsKey, - this::get, - this::lastEntry, - this::firstEntry - ); - } - - @Override - public @NonNull VectorMap remove(@NonNull K key) { - int keyHash = SequencedEntry.keyHash(key); - var details = new ChangeEvent>(); - BitmapIndexedNode> newRoot = remove(null, - new SequencedEntry<>(key), - keyHash, 0, details, SequencedEntry::keyEquals); - if (details.isModified()) { - var oldElem = details.getOldDataNonNull(); - var result = SequencedData.vecRemove(vector, oldElem, offset); - return size == 1 ? VectorMap.of() : renumber(newRoot, result.first(), size - 1, result.second()); - } - return this; - } - - - @Override - public @NonNull VectorMap removeAll(@NonNull Iterable c) { - var t = toMutable(); - t.removeAll(c); - return t.toImmutable(); - } - - @NonNull - private VectorMap renumber( - BitmapIndexedNode> root, - VectorList vector, - int size, int offset) { - - if (SequencedData.vecMustRenumber(size, offset, this.vector.size())) { - var result = SequencedData.vecRenumber( - new IdentityObject(), size, root, vector, SequencedEntry::entryKeyHash, SequencedEntry::keyEquals, - (e, seq) -> new SequencedEntry<>(e.getKey(), e.getValue(), seq)); - return new VectorMap<>( - result.first(), result.second(), - size, 0); - } - return new VectorMap<>(root, vector, size, offset); - } - - @Override - public @NonNull VectorMap retainAll(@NonNull Iterable c) { - var m = toMutable(); - m.retainAll(c); - return m.toImmutable(); - } - - @NonNull Iterator> reverseIterator() { - return Spliterators.iterator(reverseSpliterator()); - } - - @SuppressWarnings("unchecked") - @NonNull Spliterator> reverseSpliterator() { - return new ReverseTombSkippingVectorSpliterator<>(vector, - e -> ((SequencedEntry) e), - size(), Spliterator.SIZED | Spliterator.DISTINCT | Spliterator.ORDERED | Spliterator.IMMUTABLE); - } - - - @Override - public int size() { - return size; - } - - public @NonNull Spliterator> spliterator() { - return new TombSkippingVectorSpliterator<>(vector, - e -> ((Map.Entry) e), - 0, size(), Spliterator.SIZED | Spliterator.DISTINCT | Spliterator.ORDERED | Spliterator.IMMUTABLE); - } - - /** - * Creates a mutable copy of this map. - * - * @return a mutable sequenced CHAMP map - */ - @Override - public @NonNull MutableVectorMap toMutable() { - return new MutableVectorMap<>(this); - } - - @Override - public @NonNull MutableVectorMap asMap() { - return new MutableVectorMap<>(this); - } - - - @Override - public Transformer> transformed() { - return this::transform; - } - - private R transform(Function, ? extends R> f) { - return f.apply(this); - } - - @Override - public @NonNull String toString() { - return ReadOnlyMap.mapToString(this); - } - - @Serial - private @NonNull Object writeReplace() throws ObjectStreamException { - return new SerializationProxy<>(this.toMutable()); - } - - private static class SerializationProxy extends MapSerializationProxy { - @Serial - private static final long serialVersionUID = 0L; - - protected SerializationProxy(Map target) { - super(target); - } - - @Serial - @Override - protected @NonNull Object readResolve() { - return VectorMap.of().putAll(deserialized); - } - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorSet.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorSet.java deleted file mode 100644 index 904c596c6..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorSet.java +++ /dev/null @@ -1,466 +0,0 @@ -/* - * @(#)VectorSet.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection; - - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.facade.ReadOnlySequencedSetFacade; -import org.jhotdraw8.collection.immutable.ImmutableSequencedSet; -import org.jhotdraw8.collection.impl.IdentityObject; -import org.jhotdraw8.collection.impl.champ.*; -import org.jhotdraw8.collection.readonly.ReadOnlyCollection; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedSet; -import org.jhotdraw8.collection.readonly.ReadOnlySet; -import org.jhotdraw8.collection.serialization.SetSerializationProxy; -import org.jhotdraw8.collection.transform.Transformer; - -import java.io.Serial; -import java.io.Serializable; -import java.util.*; -import java.util.function.Function; - - -/** - * Implements the {@link ImmutableSequencedSet} interface using a Compressed - * Hash-Array Mapped Prefix-tree (CHAMP) and a bit-mapped trie (Vector). - *

- * Features: - *

    - *
  • supports up to 230 elements
  • - *
  • allows null elements
  • - *
  • is immutable
  • - *
  • is thread-safe
  • - *
  • iterates in the order, in which elements were inserted
  • - *
- *

- * Performance characteristics: - *

    - *
  • add: O(log N) in an amortized sense, because we sometimes have to - * renumber the elements.
  • - *
  • remove: O(log N) in an amortized sense, because we sometimes have to - * renumber the elements.
  • - *
  • contains: O(1)
  • - *
  • toMutable: O(1) + O(log N) distributed across subsequent updates in - * the mutable copy
  • - *
  • clone: O(1)
  • - *
  • iterator creation: O(1)
  • - *
  • iterator.next: O(log N)
  • - *
  • getFirst(), getLast(): O(log N)
  • - *
- *

- * Implementation details: - *

- * This set performs read and write operations of single elements in O(log N) time, - * and in O(log N) space, where N is the number of elements in the set. - *

- * Uses a Compressed Hash-Array Mapped Prefix-tree (CHAMP) trie for storing - * the map entries. - *

- * The CHAMP trie contains nodes that may be shared with other sets. - *

- * If a write operation is performed on a node, then this set creates a - * copy of the node and of all parent nodes up to the root (copy-path-on-write). - * Since the CHAMP trie has a fixed maximal height, the cost is O(1). - *

- * This set can create a mutable copy of itself in O(1) time and O(1) space - * using method {@link #toMutable()}. The mutable copy shares its nodes - * with this set, until it has gradually replaced the nodes with exclusively - * owned nodes. - *

- * Insertion Order: - *

- * This set uses a counter to keep track of the insertion order. - * It stores the current value of the counter in the sequence number - * field of each data entry. If the counter wraps around, it must renumber all - * sequence numbers. - *

- * The renumbering is why the {@code add} and {@code remove} methods are O(1) - * only in an amortized sense. - *

- * To support iteration, we use a Vector. The Vector has the same contents - * as the CHAMP trie. However, its elements are stored in insertion order. - *

- * If an element is removed from the CHAMP trie that is not the first or the - * last element of the Vector, we replace its corresponding element in - * the Vector by a tombstone. If the element is at the start or end of the Vector, - * we remove the element and all its neighboring tombstones from the Vector. - *

- * A tombstone can store the number of neighboring tombstones in ascending and in descending - * direction. We use these numbers to skip tombstones when we iterate over the vector. - * Since we only allow iteration in ascending or descending order from one of the ends of - * the vector, we do not need to keep the number of neighbors in all tombstones up to date. - * It is sufficient, if we update the neighbor with the lowest index and the one with the - * highest index. - *

- * If the number of tombstones exceeds half of the size of the collection, we renumber all - * sequence numbers, and we create a new Vector. - *

- * The immutable version of this set extends from the non-public class - * {@code ChampBitmapIndexNode}. This design safes 16 bytes for every instance, - * and reduces the number of redirections for finding an element in the - * collection by 1. - *

- * References: - *

- * For a similar design, see 'VectorMap.scala'. Note, that this code is not a derivative - * of that code. - *

- *
The Scala library. VectorMap.scala. Copyright EPFL and Lightbend, Inc. Apache License 2.0.
- *
github.com - *
- *
- * - * @param the element type - */ -@SuppressWarnings("exports") -public class VectorSet - extends BitmapIndexedNode> - implements Serializable, ImmutableSequencedSet { - private static final @NonNull VectorSet EMPTY = new VectorSet<>( - BitmapIndexedNode.emptyNode(), VectorList.of(), 0, 0); - @Serial - private static final long serialVersionUID = 0L; - /** - * Offset of sequence numbers to vector indices. - * - *
vector index = sequence number + offset
- */ - final int offset; - /** - * The size of the set. - */ - final int size; - /** - * In this vector we store the elements in the order in which they were inserted. - */ - final @NonNull VectorList vector; - - VectorSet( - @NonNull BitmapIndexedNode> root, - @NonNull VectorList vector, - int size, int offset) { - super(root.nodeMap(), root.dataMap(), root.mixed); - this.size = size; - this.offset = offset; - this.vector = Objects.requireNonNull(vector); - } - - - /** - * Returns an immutable set that contains the provided elements. - * - * @param c an iterable - * @param the element type - * @return an immutable set of the provided elements - */ - - public static @NonNull VectorSet copyOf(@NonNull Iterable c) { - return VectorSet.of().addAll(c); - } - - - /** - * Returns an empty immutable set. - * - * @param the element type - * @return an empty immutable set - */ - - @SuppressWarnings("unchecked") - public static @NonNull VectorSet of() { - return ((VectorSet) VectorSet.EMPTY); - } - - - /** - * Returns an immutable set that contains the provided elements. - * - * @param elements elements - * @param the element type - * @return an immutable set of the provided elements - */ - - @SuppressWarnings({"varargs"}) - @SafeVarargs - public static @NonNull VectorSet of(E @Nullable ... elements) { - Objects.requireNonNull(elements, "elements is null"); - return VectorSet.of().addAll(Arrays.asList(elements)); - } - - @Override - public @NonNull VectorSet add(@Nullable E key) { - return addLast(key, false); - } - - @Override - public @NonNull VectorSet addAll(@NonNull Iterable c) { - var m = toMutable(); - m.addAll(c); - return m.toImmutable(); - } - - public @NonNull VectorSet addFirst(@Nullable E element) { - return addFirst(element, true); - } - - private @NonNull VectorSet addFirst(@Nullable E e, boolean moveToFirst) { - var details = new ChangeEvent>(); - var newElem = new SequencedElement<>(e, -offset - 1); - var newRoot = put(null, newElem, - SequencedElement.keyHash(e), 0, details, - moveToFirst ? SequencedElement::putAndMoveToFirst : SequencedElement::put, - Objects::equals, SequencedElement::elementKeyHash); - if (details.isModified()) { - var newVector = vector; - int newSize = size; - - if (details.isReplaced()) { - if (moveToFirst) { - var result = SequencedData.vecRemove(newVector, details.getOldDataNonNull(), offset); - newVector = result.first(); - } - } else { - newSize++; - } - int newOffset = offset + 1; - newVector = newVector.addFirst(newElem); - return renumber(newRoot, newVector, newSize, newOffset); - } - return this; - } - - public @NonNull VectorSet addLast(@Nullable E element) { - return addLast(element, true); - } - - private @NonNull VectorSet addLast(@Nullable E e, - boolean moveToLast) { - var details = new ChangeEvent>(); - var newElem = new SequencedElement<>(e, vector.size() - offset); - var newRoot = put(null, newElem, - SequencedElement.keyHash(e), 0, details, - moveToLast ? SequencedElement::putAndMoveToLast : SequencedElement::put, - Objects::equals, SequencedElement::elementKeyHash); - if (details.isModified()) { - var newVector = vector; - int newOffset = offset; - int newSize = size; - if (details.isReplaced()) { - if (moveToLast) { - var oldElem = details.getOldData(); - var result = SequencedData.vecRemove(newVector, oldElem, newOffset); - newVector = result.first(); - newOffset = result.second(); - } - } else { - newSize++; - } - newVector = newVector.addLast(newElem); - return renumber(newRoot, newVector, newSize, newOffset); - } - return this; - } - - /** - * {@inheritDoc} - */ - @Override - public @NonNull VectorSet clear() { - return isEmpty() ? this : of(); - } - - @Override - public boolean contains(@Nullable final Object o) { - @SuppressWarnings("unchecked") final E key = (E) o; - return find(new SequencedElement<>(key), SequencedElement.keyHash(key), 0, Objects::equals) != Node.NO_DATA; - } - - @Override - public boolean equals(@Nullable Object other) { - if (other == this) { - return true; - } - if (other == null) { - return false; - } - if (other instanceof VectorSet) { - VectorSet that = (VectorSet) other; - return size == that.size && equivalent(that); - } else { - return ReadOnlySet.setEquals(this, other); - } - } - - @SuppressWarnings("unchecked") - @Override - public E getFirst() { - return ((SequencedElement) vector.getFirst()).getElement(); - } - - @SuppressWarnings("unchecked") - @Override - public E getLast() { - return ((SequencedElement) vector.getLast()).getElement(); - } - - @Override - public int hashCode() { - return ReadOnlySet.iteratorToHashCode(iterator()); - } - - @Override - public @NonNull Iterator iterator() { - return Spliterators.iterator(spliterator()); - } - - @Override - public long maxSize() { - return 1 << 30; - } - - @Override - public @NonNull ReadOnlySequencedSet readOnlyReversed() { - return new ReadOnlySequencedSetFacade<>( - this::reverseIterator, - this::iterator, - this::size, - this::contains, - this::getLast, - this::getFirst - ); - } - - @Override - public @NonNull VectorSet remove(@Nullable E key) { - int keyHash = SequencedElement.keyHash(key); - var details = new ChangeEvent>(); - BitmapIndexedNode> newRoot = remove(null, - new SequencedElement<>(key), - keyHash, 0, details, Objects::equals); - if (details.isModified()) { - var removedElem = details.getOldDataNonNull(); - var result = SequencedData.vecRemove(vector, removedElem, offset); - return size == 1 ? VectorSet.of() : renumber(newRoot, result.first(), size - 1, - result.second()); - } - return this; - } - - - @Override - public @NonNull VectorSet removeAll(@NonNull Iterable c) { - var m = toMutable(); - m.removeAll(c); - return m.toImmutable(); - } - - @Override - public VectorSet removeFirst() { - return remove(getFirst()); - } - - @Override - public VectorSet removeLast() { - return remove(getLast()); - } - - /** - * Renumbers the sequenced elements in the trie if necessary. - * - * @param root the root of the trie - * @param vector the root of the vector - * @param size the size of the trie - * @param offset the offset that must be added to a sequence number to get the index into the vector - * @return a new {@link VectorSet} instance - */ - @NonNull - private VectorSet renumber( - BitmapIndexedNode> root, - VectorList vector, - int size, int offset) { - - if (SequencedData.vecMustRenumber(size, offset, this.vector.size())) { - var owner = new IdentityObject(); - var result = SequencedData.vecRenumber( - new IdentityObject(), size, root, vector, SequencedElement::elementKeyHash, Objects::equals, - (e, seq) -> new SequencedElement<>(e.getElement(), seq)); - return new VectorSet<>( - result.first(), result.second(), - size, 0); - } - return new VectorSet<>(root, vector, size, offset); - } - - @Override - public @NonNull VectorSet retainAll(@NonNull Iterable c) { - var m = toMutable(); - m.retainAll(c); - return m.toImmutable(); - } - - @NonNull Iterator reverseIterator() { - return Spliterators.iterator(reverseSpliterator()); - } - - @SuppressWarnings("unchecked") - @NonNull Spliterator reverseSpliterator() { - return new ReverseTombSkippingVectorSpliterator<>(vector, - e -> ((SequencedElement) e).getElement(), - size(), Spliterator.SIZED | Spliterator.DISTINCT | Spliterator.ORDERED | Spliterator.IMMUTABLE); - } - - @Override - public int size() { - return size; - } - - @SuppressWarnings("unchecked") - @Override - public @NonNull Spliterator spliterator() { - return new TombSkippingVectorSpliterator<>(vector, - e -> ((SequencedElement) e).getElement(), - 0, size(), Spliterator.SIZED | Spliterator.DISTINCT | Spliterator.ORDERED | Spliterator.IMMUTABLE); - } - - @Override - public @NonNull MutableVectorSet toMutable() { - return new MutableVectorSet<>(this); - } - - @Override - public Transformer> transformed() { - return this::transform; - } - - private R transform(Function, ? extends R> f) { - return f.apply(this); - } - - @Override - public @NonNull String toString() { - return ReadOnlyCollection.iterableToString(this); - } - - @Serial - private @NonNull Object writeReplace() { - return new SerializationProxy<>(toMutable()); - } - - private static class SerializationProxy extends SetSerializationProxy { - @Serial - private static final long serialVersionUID = 0L; - - protected SerializationProxy(Set target) { - super(target); - } - - @Serial - @Override - protected @NonNull Object readResolve() { - return VectorSet.copyOf(deserialized); - } - } -} \ No newline at end of file diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/computed/ComputedList.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/computed/ComputedList.java index 83b06f348..2e9f1fac2 100644 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/computed/ComputedList.java +++ b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/computed/ComputedList.java @@ -2,8 +2,8 @@ package org.jhotdraw8.collection.computed; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.readonly.AbstractReadOnlyList; -import org.jhotdraw8.collection.readonly.SizeLimitExceededException; +import org.jhotdraw8.icollection.exception.SizeLimitExceededException; +import org.jhotdraw8.icollection.readonly.AbstractReadOnlyList; import java.util.function.LongFunction; @@ -78,7 +78,7 @@ public int size() { return size > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) size; } - @Override + //@Override public long sizeAsLong() { return size; } diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/CollectionFacade.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/CollectionFacade.java deleted file mode 100755 index 701f1762c..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/CollectionFacade.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * @(#)CollectionFacade.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.facade; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.readonly.ReadOnlyCollection; - -import java.util.AbstractCollection; -import java.util.Collection; -import java.util.Iterator; -import java.util.function.IntSupplier; -import java.util.function.Predicate; -import java.util.function.Supplier; -import java.util.stream.Stream; - -/** - * Wraps {@code Collection} functions in the {@link Collection} interface. - * - * @param the element type - * @author Werner Randelshofer - */ -public class CollectionFacade extends AbstractCollection implements ReadOnlyCollection { - protected final @NonNull Supplier> iteratorFunction; - protected final @NonNull IntSupplier sizeFunction; - protected final @NonNull Predicate containsFunction; - protected final @NonNull Runnable clearFunction; - protected final @NonNull Predicate removeFunction; - - public CollectionFacade(@NonNull ReadOnlyCollection backingCollection) { - this(backingCollection::iterator, backingCollection::size, - backingCollection::contains, null, null); - } - - public CollectionFacade(@NonNull Collection backingCollection) { - this(backingCollection::iterator, backingCollection::size, - backingCollection::contains, backingCollection::clear, backingCollection::remove); - } - - public CollectionFacade(@NonNull Supplier> iteratorFunction, - @NonNull IntSupplier sizeFunction, - @NonNull Predicate containsFunction) { - this(iteratorFunction, sizeFunction, containsFunction, null, null); - } - - public CollectionFacade(@NonNull Supplier> iteratorFunction, - @NonNull IntSupplier sizeFunction, - @NonNull Predicate containsFunction, - @Nullable Runnable clearFunction, - @Nullable Predicate removeFunction) { - this.iteratorFunction = iteratorFunction; - this.sizeFunction = sizeFunction; - this.containsFunction = containsFunction; - this.clearFunction = clearFunction == null ? () -> { - throw new UnsupportedOperationException(); - } : clearFunction; - this.removeFunction = removeFunction == null ? o -> { - throw new UnsupportedOperationException(); - } : removeFunction; - } - - @Override - public boolean remove(Object o) { - return removeFunction.test(o); - } - - @Override - public void clear() { - clearFunction.run(); - } - - @Override - public Stream stream() { - return super.stream(); - } - - @Override - public @NonNull Iterator iterator() { - return iteratorFunction.get(); - } - - @Override - public int size() { - return sizeFunction.getAsInt(); - } - - @Override - public boolean contains(Object o) { - return containsFunction.test(o); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ImmutableMapFacade.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ImmutableMapFacade.java deleted file mode 100644 index 6f29a8b7e..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ImmutableMapFacade.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * @(#)ImmutableMapFacade.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.facade; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableMap; -import org.jhotdraw8.collection.iterator.Iterators; -import org.jhotdraw8.collection.readonly.AbstractReadOnlyMap; -import org.jhotdraw8.collection.readonly.ReadOnlyCollection; -import org.jhotdraw8.collection.transform.Transformer; - -import java.util.*; -import java.util.function.Function; - -/** - * Wraps {@code Map} functions in the {@link ImmutableMap} interface. - * - * @param the key type - * @param the element type - */ -public class ImmutableMapFacade extends AbstractReadOnlyMap implements ImmutableMap { - - private final @NonNull Map target; - private final @NonNull Function, Map> cloneFunction; - - public ImmutableMapFacade(@NonNull Map target, @NonNull Function, Map> cloneFunction) { - this.target = target; - this.cloneFunction = cloneFunction; - } - - @Override - public @NonNull ImmutableMapFacade clear() { - if (isEmpty()) { - return this; - } - Map clone = cloneFunction.apply(target); - clone.clear(); - return new ImmutableMapFacade<>(clone, cloneFunction); - } - - @Override - public @NonNull ImmutableMapFacade put(@NonNull K key, @Nullable V value) { - if (containsKey(key) && Objects.equals(get(key), value)) { - return this; - } - Map clone = cloneFunction.apply(target); - clone.put(key, value); - return new ImmutableMapFacade<>(clone, cloneFunction); - } - - - @Override - public @NonNull ImmutableMapFacade putAll(@NonNull Iterable> c) { - Map clone = cloneFunction.apply(target); - for (Map.Entry e : c) { - clone.put(e.getKey(), e.getValue()); - } - if (clone.equals(target)) { - return this; - } - return new ImmutableMapFacade<>(clone, cloneFunction); - } - - @Override - public @NonNull ImmutableMapFacade remove(@NonNull K key) { - if (!containsKey(key)) { - return this; - } - Map clone = cloneFunction.apply(target); - clone.remove(key); - return new ImmutableMapFacade<>(clone, cloneFunction); - } - - @SuppressWarnings("SuspiciousMethodCalls") - @Override - public @NonNull ImmutableMapFacade removeAll(@NonNull Iterable c) { - if (isEmpty()) { - return this; - } - Map clone = cloneFunction.apply(target); - if (c instanceof Collection) { - Collection coll = (Collection) c; - if (coll.isEmpty()) { - return this; - } - clone.keySet().removeAll(coll); - } else { - boolean changed = false; - for (K k : c) { - changed |= clone.containsKey(k); - clone.remove(k); - } - if (!changed) { - return this; - } - } - return new ImmutableMapFacade<>(clone, cloneFunction); - } - - @SuppressWarnings("unchecked") - @Override - public @NonNull ImmutableMapFacade retainAll(@NonNull Iterable c) { - if (isEmpty()) return this; - Map clone = cloneFunction.apply(target); - Collection collection; - if (c instanceof ReadOnlyCollection rc) { - collection = (Collection) rc.asCollection(); - } else if (c instanceof Collection cc) { - collection = (Collection) cc; - } else { - collection = new HashSet(); - c.forEach(e -> collection.add(e)); - } - return clone.keySet().retainAll(collection) ? new ImmutableMapFacade<>(clone, cloneFunction) : this; - } - - @Override - public boolean isEmpty() { - return target.isEmpty(); - } - - @Override - public @NonNull Iterator> iterator() { - return Iterators.unmodifiableIterator(target.entrySet().iterator()); - } - - @Override - public int size() { - return target.size(); - } - - @SuppressWarnings("SuspiciousMethodCalls") - @Override - public @Nullable V get(Object key) { - return target.get(key); - } - - @SuppressWarnings("SuspiciousMethodCalls") - @Override - public boolean containsKey(@Nullable Object key) { - return target.containsKey(key); - } - - @Override - public @NonNull Map toMutable() { - return cloneFunction.apply(target); - } - - @Override - public Transformer> transformed() { - return this::transform; - } - - private R transform(Function, ? extends R> f) { - return f.apply(this); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ImmutableSetFacade.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ImmutableSetFacade.java deleted file mode 100644 index 3d4d30302..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ImmutableSetFacade.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * @(#)ImmutableSetFacade.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.facade; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableSet; -import org.jhotdraw8.collection.iterator.Iterators; -import org.jhotdraw8.collection.readonly.AbstractReadOnlySet; -import org.jhotdraw8.collection.readonly.ReadOnlyCollection; -import org.jhotdraw8.collection.transform.Transformer; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.function.Function; - -/** - * Wraps {@code Set} functions in the {@link ImmutableSet} interface. - * - * @param the element type - */ -public class ImmutableSetFacade extends AbstractReadOnlySet implements ImmutableSet { - private final @NonNull Set target; - private final @NonNull Function, Set> cloneFunction; - - public ImmutableSetFacade(@NonNull Set target, @NonNull Function, Set> cloneFunction) { - this.target = target; - this.cloneFunction = cloneFunction; - } - - @Override - public @NonNull ImmutableSet clear() { - if (isEmpty()) { - return this; - } - Set clone = cloneFunction.apply(target); - clone.clear(); - return new ImmutableSetFacade<>(clone, cloneFunction); - } - - @Override - public @NonNull ImmutableSet add(E element) { - Set clone = cloneFunction.apply(target); - return clone.add(element) ? new ImmutableSetFacade<>(clone, cloneFunction) : this; - } - - @Override - public @NonNull ImmutableSet addAll(@NonNull Iterable c) { - Set clone = cloneFunction.apply(target); - boolean changed = false; - for (E e : c) { - changed |= clone.add(e); - } - return changed ? new ImmutableSetFacade<>(clone, cloneFunction) : this; - } - - @Override - public @NonNull ImmutableSet remove(E element) { - Set clone = cloneFunction.apply(target); - return clone.remove(element) ? new ImmutableSetFacade<>(clone, cloneFunction) : this; - } - - @Override - public @NonNull ImmutableSet removeAll(@NonNull Iterable c) { - Set clone = cloneFunction.apply(target); - boolean changed = false; - for (Object e : c) { - changed |= clone.remove(e); - } - return changed ? new ImmutableSetFacade<>(clone, cloneFunction) : this; - } - - @SuppressWarnings("unchecked") - @Override - public @NonNull ImmutableSet retainAll(@NonNull Iterable c) { - if (isEmpty()) return this; - Set clone = cloneFunction.apply(target); - Collection collection; - if (c instanceof ReadOnlyCollection rc) { - collection = (Collection) rc.asCollection(); - } else if (c instanceof Collection cc) { - collection = (Collection) cc; - } else { - collection = new HashSet(); - c.forEach(e -> collection.add((E) e)); - } - return clone.retainAll(collection) ? new ImmutableSetFacade<>(clone, cloneFunction) : this; - } - - @Override - public int size() { - return target.size(); - } - - @Override - public boolean contains(Object o) { - return target.contains(o); - } - - @Override - public @NonNull Iterator iterator() { - return Iterators.unmodifiableIterator(target.iterator()); - } - - @Override - public @NonNull Set toMutable() { - return cloneFunction.apply(target); - } - - @Override - public Transformer> transformed() { - return this::transform; // method reference - } - - private R transform(Function, ? extends R> f) { - return f.apply(this); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ListFacade.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ListFacade.java deleted file mode 100755 index c35314ac9..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ListFacade.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * @(#)ListFacade.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.facade; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.readonly.ReadOnlyList; -import org.jhotdraw8.collection.sequenced.SequencedCollection; -import org.jhotdraw8.collection.spliterator.ReverseListSpliterator; - -import java.util.AbstractList; -import java.util.List; -import java.util.Spliterator; -import java.util.function.BiConsumer; -import java.util.function.IntFunction; -import java.util.function.IntSupplier; -import java.util.stream.Stream; - -/** - * Wraps {@code List} functions in the {@link List} interface. - * - * @param the element type - * @author Werner Randelshofer - */ -public class ListFacade extends AbstractList - implements SequencedCollection { - private final @NonNull IntSupplier sizeFunction; - private final @NonNull IntFunction getFunction; - private final @NonNull BiConsumer addFunction; - private final @NonNull IntFunction removeFunction; - private final @NonNull Runnable clearFunction; - - public ListFacade(@NonNull ReadOnlyList backingList) { - this(backingList::size, backingList::get, null, null, null); - } - - public ListFacade(@NonNull List backingList) { - this(backingList::size, backingList::get, backingList::clear, - backingList::add, backingList::remove); - } - - public ListFacade(@NonNull IntSupplier sizeFunction, - @NonNull IntFunction getFunction - ) { - this(sizeFunction, getFunction, null, null, null); - } - - public ListFacade(@NonNull IntSupplier sizeFunction, - @NonNull IntFunction getFunction, - @Nullable Runnable clearFunction, - @Nullable BiConsumer addFunction, - @Nullable IntFunction removeFunction - ) { - this.sizeFunction = sizeFunction; - this.getFunction = getFunction; - this.addFunction = addFunction == null ? (i, e) -> { - throw new UnsupportedOperationException(); - } : addFunction; - this.clearFunction = clearFunction == null ? () -> { - throw new UnsupportedOperationException(); - } : clearFunction; - this.removeFunction = removeFunction == null ? (i) -> { - throw new UnsupportedOperationException(); - } : removeFunction; - } - - @Override - public E get(int index) { - return getFunction.apply(index); - } - - @Override - public E getFirst() { - return SequencedCollection.super.getFirst(); - } - - @Override - public E getLast() { - return SequencedCollection.super.getLast(); - } - - @Override - public Spliterator spliterator() { - return super.spliterator(); - } - - @Override - public E remove(int index) { - return removeFunction.apply(index); - } - - @Override - public int size() { - return sizeFunction.getAsInt(); - } - - @Override - public void addFirst(E e) { - addFunction.accept(0, e); - } - - @Override - public void addLast(E e) { - addFunction.accept(size(), e); - } - - @Override - public Stream stream() { - return super.stream(); - } - - @Override - public @NonNull SequencedCollection _reversed() { - return new SequencedCollectionFacade<>( - () -> new ReverseListSpliterator<>(this, 0, size()), - this::iterator, - sizeFunction, - this::contains, - clearFunction, - this::remove, - this::getLast, - this::getFirst, - this::addLast, - this::addFirst - ); - } - - @Override - public E removeFirst() { - return SequencedCollection.super.removeFirst(); - } - - @Override - public E removeLast() { - return SequencedCollection.super.removeLast(); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/MapFacade.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/MapFacade.java deleted file mode 100755 index 5c237cf32..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/MapFacade.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * @(#)MapFacade.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.facade; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.readonly.ReadOnlyMap; - -import java.util.*; -import java.util.function.*; - -/** - * Wraps {@code Map} functions into the {@link java.util.Map} interface. - * - * @param the key type - * @param the value type - * @author Werner Randelshofer - */ -public class MapFacade extends AbstractMap { - protected final @NonNull Supplier>> iteratorFunction; - protected final @NonNull Supplier>> spliteratorFunction; - protected final @NonNull IntSupplier sizeFunction; - protected final @NonNull Predicate containsKeyFunction; - protected final @NonNull Runnable clearFunction; - protected final @NonNull Function removeFunction; - protected final @NonNull Function getFunction; - protected final @NonNull BiFunction putFunction; - - - public MapFacade(@NonNull ReadOnlyMap m) { - this(m::iterator, m::spliterator, m::size, m::containsKey, m::get, null, null, null); - } - - public MapFacade(@NonNull Map m) { - this(() -> m.entrySet().iterator(), () -> m.entrySet().spliterator(), m::size, m::containsKey, m::get, m::clear, - m::remove, m::put); - } - - public MapFacade(@NonNull Supplier>> iteratorFunction, - @NonNull Supplier>> spliteratorFunction, @NonNull IntSupplier sizeFunction, - @NonNull Predicate containsKeyFunction, - @NonNull Function getFunction, - @Nullable Runnable clearFunction, - @Nullable Function removeFunction, - @Nullable BiFunction putFunction) { - this.iteratorFunction = iteratorFunction; - this.spliteratorFunction = spliteratorFunction; - this.sizeFunction = sizeFunction; - this.containsKeyFunction = containsKeyFunction; - this.getFunction = getFunction; - this.clearFunction = clearFunction == null ? () -> { - throw new UnsupportedOperationException(); - } : clearFunction; - this.removeFunction = removeFunction == null ? o -> { - throw new UnsupportedOperationException(); - } : removeFunction; - this.putFunction = putFunction == null ? (k, v) -> { - throw new UnsupportedOperationException(); - } : putFunction; - } - - @Override - public V get(Object key) { - @SuppressWarnings("unchecked") K unchecked = (K) key; - return getFunction.apply(unchecked); - } - - @Override - public boolean containsKey(Object key) { - return containsKeyFunction.test(key); - } - - @Override - public int size() { - return sizeFunction.getAsInt(); - } - - public boolean containsEntry(final @Nullable Object o) { - if (o instanceof Entry) { - @SuppressWarnings("unchecked") Entry entry = (Entry) o; - K key = entry.getKey(); - return containsKey(key) && Objects.equals(entry.getValue(), get(key)); - } - return false; - } - - boolean removeEntry(final @Nullable Object o) { - if (containsEntry(o)) { - assert o != null; - @SuppressWarnings("unchecked") Entry entry = (Entry) o; - remove(entry.getKey()); - return true; - } - return false; - } - - @Override - public @NonNull Set> entrySet() { - return new SetFacade<>( - iteratorFunction, - spliteratorFunction, sizeFunction, - this::containsEntry, - clearFunction, - null, - this::removeEntry - ); - } - - @Override - public V getOrDefault(Object key, V defaultValue) { - return super.getOrDefault(key, defaultValue); - } - - @Override - public V remove(Object key) { - return removeFunction.apply(key); - } - - @Override - public V put(K key, V value) { - return putFunction.apply(key, value); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/MutableListFacade.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/MutableListFacade.java deleted file mode 100755 index 5e15ba4e9..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/MutableListFacade.java +++ /dev/null @@ -1,296 +0,0 @@ -/* - * @(#)MutableListFacade.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.facade; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableList; -import org.jhotdraw8.collection.iterator.FailFastIterator; -import org.jhotdraw8.collection.iterator.FailFastListIterator; -import org.jhotdraw8.collection.readonly.ReadOnlyList; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedCollection; -import org.jhotdraw8.collection.sequenced.SequencedCollection; -import org.jhotdraw8.collection.spliterator.FailFastSpliterator; - -import java.util.AbstractList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.NoSuchElementException; -import java.util.Objects; -import java.util.Spliterator; -import java.util.stream.Stream; - -/** - * Wraps {@link ImmutableList} functions into the {@link List} interface. - * - * @param the element type - * @author Werner Randelshofer - */ -public class MutableListFacade extends AbstractList implements ReadOnlyList, SequencedCollection { - private @NonNull ImmutableList backingList; - private int modCount; - - public MutableListFacade(@NonNull ImmutableList backingList) { - this.backingList = backingList; - } - - @Override - public void addFirst(E e) { - backingList = backingList.add(0, e); - modCount++; - } - - @Override - public void addLast(E e) { - backingList = backingList.add(e); - modCount++; - } - - @Override - public @NonNull SequencedCollection _reversed() { - return new SequencedCollectionFacade( - this::reverseIterator, - this::iterator, - this::size, - this::contains - ); - } - - @Override - public @NonNull ReadOnlySequencedCollection readOnlyReversed() { - return new ReadOnlyListFacade<>( - () -> backingList.size(), - index -> get(backingList.size() - 1 - index), - () -> this); - } - - - @Override - public boolean remove(Object o) { - ImmutableList oldList = backingList; - backingList = backingList.remove((E) o); - modCount++; - return oldList != backingList; - } - - @Override - public E remove(int index) { - E removed = backingList.get(index); - backingList = backingList.removeAt(index); - modCount++; - return removed; - } - - - @Override - public void clear() { - ImmutableList oldList = backingList; - backingList = backingList.clear(); - if (oldList != backingList) modCount++; - } - - @Override - public @NonNull Spliterator spliterator() { - return new FailFastSpliterator<>(backingList.spliterator(), () -> this.modCount); - } - - @Override - public @NonNull ReadOnlyList readOnlySubList(int fromIndex, int toIndex) { - return null; - } - - @Override - public Stream stream() { - return backingList.stream(); - } - - @Override - public @NonNull Iterator iterator() { - Iterator it = new MyIterator<>(backingList.iterator()); - return new FailFastIterator<>(it, () -> this.modCount); - } - - - public @NonNull Iterator reverseIterator() { - Iterator it = new MyIterator<>(backingList.readOnlyReversed().iterator()); - return new FailFastIterator<>(it, () -> this.modCount); - } - - - @Override - public int size() { - return backingList.size(); - } - - @Override - public boolean contains(Object o) { - return backingList.contains(o); - } - - class MyIterator implements Iterator { - final @NonNull Iterator b; - @Nullable E current; - boolean canRemove; - - MyIterator(@NonNull Iterator b) { - this.b = b; - } - - @Override - public boolean hasNext() { - return b.hasNext(); - } - - @Override - public E next() { - current = b.next(); - canRemove = true; - return current; - } - - @Override - public void remove() { - if (canRemove) { - MutableListFacade.this.remove(current); - canRemove = false; - } else { - throw new IllegalStateException(); - } - } - } - - class MyListIterator implements ListIterator { - int index; - @Nullable E current; - int prevIndex = -1; - - MyListIterator(int index) { - this.index = index; - } - - @Override - public boolean hasNext() { - return index < size(); - } - - @Override - public E next() { - if (!hasNext()) throw new NoSuchElementException(); - prevIndex = index; - current = get(index++); - return current; - } - - @Override - public boolean hasPrevious() { - return index > 0; - } - - @Override - public E previous() { - if (!hasPrevious()) throw new NoSuchElementException(); - current = get(--index); - prevIndex = index; - return current; - } - - @Override - public int nextIndex() { - return index; - } - - @Override - public int previousIndex() { - return index - 1; - } - - @Override - public void remove() { - if (prevIndex >= 0 && prevIndex < size()) { - MutableListFacade.this.remove(prevIndex); - index = prevIndex; - prevIndex = -1; - } else { - throw new IllegalStateException(); - } - } - - @Override - public void set(E e) { - if (prevIndex >= 0 && prevIndex < size()) { - MutableListFacade.this.set(prevIndex, e); - } else { - throw new IllegalStateException(); - } - } - - @Override - public void add(E e) { - if (index >= 0 && index <= size()) { - MutableListFacade.this.add(index++, e); - prevIndex = -1; - } else { - throw new IllegalStateException(); - } - - } - } - - @Override - public boolean add(E e) { - ImmutableList oldList = backingList; - backingList = backingList.add(e); - if (oldList != backingList) { - modCount++; - return true; - } - return false; - } - - @Override - public void add(int index, E e) { - backingList = backingList.add(index, e); - modCount++; - } - - @Override - public E set(int index, E e) { - E oldValue = backingList.get(index); - backingList = backingList.set(index, e); - return oldValue; - } - - @Override - public E get(int index) { - return backingList.get(index); - } - - @Override - public E getFirst() { - return ReadOnlyList.super.getFirst(); - } - - @Override - public E getLast() { - return ReadOnlyList.super.getLast(); - } - - @Override - public @NonNull ListIterator listIterator(int index) { - Objects.checkIndex(index, size() + 1); - return new FailFastListIterator<>(new MyListIterator(index), () -> this.modCount); - } - - @Override - public E removeFirst() { - return SequencedCollection.super.removeFirst(); - } - - @Override - public E removeLast() { - return SequencedCollection.super.removeLast(); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/MutableSetFacade.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/MutableSetFacade.java deleted file mode 100755 index 033b43295..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/MutableSetFacade.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * @(#)MutableSetFacade.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.facade; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableSet; -import org.jhotdraw8.collection.iterator.FailFastIterator; -import org.jhotdraw8.collection.readonly.ReadOnlySet; -import org.jhotdraw8.collection.spliterator.FailFastSpliterator; - -import java.util.AbstractSet; -import java.util.Iterator; -import java.util.Set; -import java.util.Spliterator; -import java.util.stream.Stream; - -/** - * Wraps {@link ImmutableSet} functions into the {@link Set} interface. - * - * @param the element type - * @author Werner Randelshofer - */ -public class MutableSetFacade extends AbstractSet implements ReadOnlySet { - private @NonNull ImmutableSet backingSet; - private int modCount; - - public MutableSetFacade(@NonNull ImmutableSet backingSet) { - this.backingSet = backingSet; - } - - - @Override - public boolean remove(Object o) { - ImmutableSet oldSet = backingSet; - backingSet = backingSet.remove((E) o); - if (oldSet != backingSet) { - modCount++; - return true; - } - return false; - } - - @Override - public void clear() { - ImmutableSet oldSet = backingSet; - backingSet = backingSet.clear(); - if (oldSet != backingSet) modCount++; - } - - @Override - public Spliterator spliterator() { - return new FailFastSpliterator<>(backingSet.spliterator(), () -> this.modCount); - } - - @Override - public Stream stream() { - return backingSet.stream(); - } - - @Override - public @NonNull Iterator iterator() { - Iterator it = new Iterator<>() { - final Iterator b = backingSet.iterator(); - E current; - boolean canRemove; - - @Override - public boolean hasNext() { - return b.hasNext(); - } - - @Override - public E next() { - current = b.next(); - canRemove = true; - return current; - } - - @Override - public void remove() { - if (canRemove) { - MutableSetFacade.this.remove(current); - canRemove = false; - } else { - throw new IllegalStateException(); - } - } - }; - - return new FailFastIterator<>(it, () -> this.modCount); - } - - - @Override - public int size() { - return backingSet.size(); - } - - @Override - public boolean contains(Object o) { - return backingSet.contains(o); - } - - @Override - public boolean add(E e) { - ImmutableSet oldSet = backingSet; - backingSet = backingSet.add(e); - if (oldSet != backingSet) { - modCount++; - return true; - } - return false; - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlyCollectionFacade.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlyCollectionFacade.java deleted file mode 100755 index 33369c262..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlyCollectionFacade.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * @(#)ReadOnlyCollectionFacade.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.facade; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.readonly.AbstractReadOnlyCollection; -import org.jhotdraw8.collection.readonly.ReadOnlyCollection; -import org.jhotdraw8.collection.readonly.ReadOnlySet; - -import java.util.Iterator; -import java.util.Set; -import java.util.function.IntSupplier; -import java.util.function.Predicate; -import java.util.function.Supplier; - -/** - * Wraps {@code Collection} functions into the {@link ReadOnlyCollection} interface. - * - * @param the element type - * @author Werner Randelshofer - */ -public class ReadOnlyCollectionFacade extends AbstractReadOnlyCollection { - - protected final Supplier> iteratorFunction; - protected final IntSupplier sizeFunction; - protected final Predicate containsFunction; - - public ReadOnlyCollectionFacade(@NonNull Set backingSet) { - this(backingSet::iterator, backingSet::size, backingSet::contains); - } - - public ReadOnlyCollectionFacade(Supplier> iteratorFunction, IntSupplier sizeFunction, Predicate containsFunction) { - this.iteratorFunction = iteratorFunction; - this.sizeFunction = sizeFunction; - this.containsFunction = containsFunction; - } - - @Override - public int size() { - return sizeFunction.getAsInt(); - } - - @Override - public boolean contains(Object o) { - return containsFunction.test(o); - } - - @Override - public @NonNull Iterator iterator() { - return new Iterator<>() { - private final Iterator i = iteratorFunction.get(); - - @Override - public boolean hasNext() { - return i.hasNext(); - } - - @Override - public E next() { - return i.next(); - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - }; - } - - @Override - public boolean equals(Object o) { - return ReadOnlySet.setEquals(new ReadOnlySetFacade<>(this), o); - } - - @Override - public int hashCode() { - return ReadOnlySet.iteratorToHashCode(iteratorFunction.get()); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlyListFacade.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlyListFacade.java deleted file mode 100755 index e4e130bd4..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlyListFacade.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * @(#)ReadOnlyListFacade.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.facade; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.readonly.AbstractReadOnlyList; -import org.jhotdraw8.collection.readonly.ReadOnlyList; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedCollection; - -import java.util.List; -import java.util.Objects; -import java.util.function.IntFunction; -import java.util.function.IntSupplier; -import java.util.function.Supplier; - -/** - * Wraps {@code List} functions in the {@link ReadOnlyList} interface. - * - * @param the element type - * @author Werner Randelshofer - */ -public class ReadOnlyListFacade extends AbstractReadOnlyList { - private final @NonNull IntSupplier sizeFunction; - private final @NonNull IntFunction getFunction; - private final @NonNull Supplier> readOnlyReversedFunction; - - public ReadOnlyListFacade(@NonNull List backingList) { - this.sizeFunction = backingList::size; - this.getFunction = backingList::get; - this.readOnlyReversedFunction = () -> new ReadOnlyListFacade<>( - sizeFunction, - index -> getFunction.apply(sizeFunction.getAsInt() - index), - () -> this); - } - - public ReadOnlyListFacade(@NonNull IntSupplier sizeFunction, @NonNull IntFunction getFunction, @NonNull Supplier> readOnlyReversedFunction) { - this.sizeFunction = sizeFunction; - this.getFunction = getFunction; - this.readOnlyReversedFunction = readOnlyReversedFunction; - } - - @Override - public E get(int index) { - return getFunction.apply(index); - } - - @Override - public @NonNull ReadOnlySequencedCollection readOnlyReversed() { - return readOnlyReversedFunction.get(); - } - - @Override - public @NonNull ReadOnlyList readOnlySubList(int fromIndex, int toIndex) { - int length = size(); - Objects.checkFromToIndex(fromIndex, toIndex, length); - return new ReadOnlyListFacade<>( - () -> toIndex - fromIndex, - i -> getFunction.apply(i - fromIndex), - readOnlyReversedFunction); - } - - @Override - public int size() { - return sizeFunction.getAsInt(); - } - - - @Override - public boolean equals(Object o) { - return ReadOnlyList.listEquals(this, o); - } - - @Override - public int hashCode() { - return ReadOnlyList.iteratorToHashCode(iterator()); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlyMapFacade.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlyMapFacade.java deleted file mode 100644 index 91603f595..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlyMapFacade.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * @(#)ReadOnlyMapFacade.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.facade; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.readonly.ReadOnlyMap; - -import java.util.Iterator; -import java.util.Map; -import java.util.Objects; -import java.util.function.Function; -import java.util.function.IntSupplier; -import java.util.function.Predicate; -import java.util.function.Supplier; - -/** - * Wraps {@code Map} functions in the {@link ReadOnlyMap} interface. - * - * @param the key type - * @param the value type - * @author Werner Randelshofer - */ -public class ReadOnlyMapFacade implements ReadOnlyMap { - protected final @NonNull Supplier>> iteratorFunction; - protected final @NonNull IntSupplier sizeFunction; - protected final @NonNull Predicate containsKeyFunction; - protected final @NonNull Function getFunction; - - - public ReadOnlyMapFacade(@NonNull ReadOnlyMap m) { - this(m::iterator, m::size, m::containsKey, m::get); - } - - public ReadOnlyMapFacade(@NonNull Map m) { - this(() -> m.entrySet().iterator(), m::size, m::containsKey, m::get); - } - - public ReadOnlyMapFacade(@NonNull Supplier>> iteratorFunction, - @NonNull IntSupplier sizeFunction, - @NonNull Predicate containsKeyFunction, - @NonNull Function getFunction) { - this.iteratorFunction = iteratorFunction; - this.sizeFunction = sizeFunction; - this.containsKeyFunction = containsKeyFunction; - this.getFunction = getFunction; - } - - @Override - public V get(Object key) { - @SuppressWarnings("unchecked") K unchecked = (K) key; - return getFunction.apply(unchecked); - } - - @Override - public boolean containsKey(Object key) { - return containsKeyFunction.test(key); - } - - @Override - public boolean isEmpty() { - return sizeFunction.getAsInt() == 0; - } - - @Override - public @NonNull Iterator> iterator() { - return iteratorFunction.get(); - } - - @Override - public int size() { - return sizeFunction.getAsInt(); - } - - public boolean containsEntry(final @Nullable Object o) { - if (o instanceof Map.Entry) { - @SuppressWarnings("unchecked") Map.Entry entry = (Map.Entry) o; - K key = entry.getKey(); - return containsKey(key) && Objects.equals(entry.getValue(), get(key)); - } - return false; - } - -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlySequencedMapFacade.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlySequencedMapFacade.java deleted file mode 100644 index 849e84029..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlySequencedMapFacade.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * @(#)ReadOnlySequencedMapFacade.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.facade; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedMap; -import org.jhotdraw8.collection.sequenced.SequencedMap; - -import java.util.Iterator; -import java.util.Map; -import java.util.function.Function; -import java.util.function.IntSupplier; -import java.util.function.Predicate; -import java.util.function.Supplier; - -/** - * Wraps {@code Map} functions in the {@link ReadOnlySequencedMap} interface. - * - * @param the key type - * @param the value type - * @author Werner Randelshofer - */ -public class ReadOnlySequencedMapFacade extends ReadOnlyMapFacade - implements ReadOnlySequencedMap { - private final @NonNull Supplier> firstEntryFunction; - private final @NonNull Supplier> lastEntryFunction; - private final @NonNull Supplier>> reverseIteratorFunction; - - public ReadOnlySequencedMapFacade(@NonNull SequencedMap target) { - super(target); - this.firstEntryFunction = target::firstEntry; - this.lastEntryFunction = target::lastEntry; - this.reverseIteratorFunction = () -> target._reversed()._sequencedEntrySet().iterator(); - } - - public ReadOnlySequencedMapFacade( - @NonNull Supplier>> iteratorFunction, - @NonNull Supplier>> reverseIteratorFunction, - @NonNull IntSupplier sizeFunction, - @NonNull Predicate containsKeyFunction, - @NonNull Function getFunction, - @NonNull Supplier> firstEntryFunction, - @NonNull Supplier> lastEntryFunction) { - super(iteratorFunction, sizeFunction, containsKeyFunction, getFunction); - this.firstEntryFunction = firstEntryFunction; - this.lastEntryFunction = lastEntryFunction; - this.reverseIteratorFunction = reverseIteratorFunction; - } - - @Override - public @NonNull ReadOnlySequencedMap readOnlyReversed() { - return new ReadOnlySequencedMapFacade<>( - reverseIteratorFunction, - iteratorFunction, - sizeFunction, - containsKeyFunction, - getFunction, - lastEntryFunction, - firstEntryFunction - ); - } - - @Override - public Map.@Nullable Entry firstEntry() { - return firstEntryFunction.get(); - } - - @Override - public Map.@Nullable Entry lastEntry() { - return lastEntryFunction.get(); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlySequencedSetFacade.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlySequencedSetFacade.java deleted file mode 100755 index e2960b4d5..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlySequencedSetFacade.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * @(#)ReadOnlySequencedSetFacade.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.facade; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedSet; -import org.jhotdraw8.collection.sequenced.SequencedSet; - -import java.util.Iterator; -import java.util.function.IntSupplier; -import java.util.function.Predicate; -import java.util.function.Supplier; - -/** - * Wraps {@code Set} functions into the {@link ReadOnlySequencedSet} interface. - * - * @param the element type - * @author Werner Randelshofer - */ -public class ReadOnlySequencedSetFacade extends ReadOnlySetFacade - implements ReadOnlySequencedSet { - - final @NonNull Supplier getFirstFunction; - final @NonNull Supplier getLastFunction; - final @NonNull Supplier> reverseIteratorFunction; - - public ReadOnlySequencedSetFacade(@NonNull ReadOnlySequencedSet backingSet) { - this(backingSet::iterator, () -> backingSet.readOnlyReversed().iterator(), backingSet::size, - backingSet::contains, backingSet::getFirst, backingSet::getLast); - } - - public ReadOnlySequencedSetFacade(@NonNull SequencedSet backingSet) { - this(backingSet::iterator, () -> backingSet._reversed().iterator(), backingSet::size, - backingSet::contains, backingSet::getFirst, backingSet::getLast); - } - - public ReadOnlySequencedSetFacade(@NonNull Supplier> iteratorFunction, - @NonNull Supplier> reverseIteratorFunction, - @NonNull IntSupplier sizeFunction, - @NonNull Predicate containsFunction, - @NonNull Supplier getFirstFunction, - @NonNull Supplier getLastFunction) { - super(iteratorFunction, sizeFunction, containsFunction); - this.getFirstFunction = getFirstFunction; - this.getLastFunction = getLastFunction; - this.reverseIteratorFunction = reverseIteratorFunction; - } - - - @Override - public E getFirst() { - return getFirstFunction.get(); - } - - @Override - public E getLast() { - return getLastFunction.get(); - } - - @Override - public @NonNull ReadOnlySequencedSet readOnlyReversed() { - return new ReadOnlySequencedSetFacade<>( - reverseIteratorFunction, - iteratorFunction, - sizeFunction, - containsFunction, - getLastFunction, - getFirstFunction - ); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlySetFacade.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlySetFacade.java deleted file mode 100755 index fece9e85f..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlySetFacade.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * @(#)ReadOnlySetFacade.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.facade; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.readonly.AbstractReadOnlySet; -import org.jhotdraw8.collection.readonly.ReadOnlyCollection; -import org.jhotdraw8.collection.readonly.ReadOnlySet; - -import java.util.Collection; -import java.util.Iterator; -import java.util.function.IntSupplier; -import java.util.function.Predicate; -import java.util.function.Supplier; - -/** - * Wraps {@code Set} functions into the {@link ReadOnlySet} interface. - * - * @param the element type - * @author Werner Randelshofer - */ -public class ReadOnlySetFacade extends AbstractReadOnlySet { - - protected final Supplier> iteratorFunction; - protected final IntSupplier sizeFunction; - protected final Predicate containsFunction; - - public ReadOnlySetFacade(@NonNull ReadOnlyCollection backingSet) { - this(backingSet::iterator, backingSet::size, backingSet::contains); - } - - public ReadOnlySetFacade(@NonNull Collection backingSet) { - this(backingSet::iterator, backingSet::size, backingSet::contains); - } - - public ReadOnlySetFacade(Supplier> iteratorFunction, IntSupplier sizeFunction, Predicate containsFunction) { - this.iteratorFunction = iteratorFunction; - this.sizeFunction = sizeFunction; - this.containsFunction = containsFunction; - } - - @Override - public int size() { - return sizeFunction.getAsInt(); - } - - @Override - public boolean contains(Object o) { - return containsFunction.test(o); - } - - @Override - public @NonNull Iterator iterator() { - return new Iterator<>() { - private final Iterator i = iteratorFunction.get(); - - @Override - public boolean hasNext() { - return i.hasNext(); - } - - @Override - public E next() { - return i.next(); - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - }; - } - - @Override - public boolean equals(Object o) { - return ReadOnlySet.setEquals(this, o); - } - - @Override - public int hashCode() { - return ReadOnlySet.iteratorToHashCode(iteratorFunction.get()); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlySubListFacade.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlySubListFacade.java deleted file mode 100644 index 48d7eae0f..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlySubListFacade.java +++ /dev/null @@ -1,224 +0,0 @@ -/* - * @(#)ReadOnlySubListFacade.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.facade; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.readonly.AbstractReadOnlyList; -import org.jhotdraw8.collection.readonly.ReadOnlyList; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedCollection; - -import java.util.ConcurrentModificationException; -import java.util.Iterator; -import java.util.ListIterator; -import java.util.NoSuchElementException; -import java.util.Objects; -import java.util.function.Consumer; -import java.util.function.IntSupplier; - -/** - * Wraps {@code List} functions for a sub-list in the {@link ReadOnlyList} - * interface. - * - * @param the element type - * @author Werner Randelshofer - */ -public class ReadOnlySubListFacade extends AbstractReadOnlyList { - - private final ReadOnlyList root; - private final ReadOnlySubListFacade parent; - private final int offset; - private final int size; - private final int modCount; - private final @NonNull IntSupplier modCountSupplier; - - /** - * Constructs a sublist of an arbitrary ArrayList. - */ - public ReadOnlySubListFacade(ReadOnlyList root, int fromIndex, int toIndex, @NonNull IntSupplier modCountSupplier) { - this.root = root; - this.modCountSupplier = modCountSupplier; - this.parent = null; - this.offset = fromIndex; - this.size = toIndex - fromIndex; - this.modCount = modCountSupplier.getAsInt(); - } - - /** - * Constructs a sublist of another SubList. - */ - private ReadOnlySubListFacade(ReadOnlySubListFacade parent, int fromIndex, int toIndex) { - this.root = parent.root; - this.parent = parent; - this.offset = parent.offset + fromIndex; - this.size = toIndex - fromIndex; - this.modCount = parent.modCount; - this.modCountSupplier = parent.modCountSupplier; - } - - public E get(int index) { - Objects.checkIndex(index, size); - ensureUnmodified(); - return root.get(offset + index); - } - - @Override - public @NonNull ReadOnlySequencedCollection readOnlyReversed() { - return new ReadOnlyListFacade<>( - () -> size, - index -> get(size - 1 - index), - () -> this); - } - - public int size() { - ensureUnmodified(); - return size; - } - - - public boolean equals(Object o) { - ensureUnmodified(); - return super.equals(o); - } - - public int hashCode() { - ensureUnmodified(); - return super.hashCode(); - } - - public int indexOf(Object o) { - ensureUnmodified(); - for (int i = 0; i < size; i++) { - if (Objects.equals(root.get(i + offset), o)) { - return i; - } - } - return -1; - } - - public int lastIndexOf(Object o) { - ensureUnmodified(); - for (int i = size - 1; i >= 0; i--) { - if (Objects.equals(root.get(i + offset), o)) { - return i; - } - } - return -1; - } - - public boolean contains(Object o) { - return indexOf(o) >= 0; - } - - public @NonNull Iterator iterator() { - return listIterator(); - } - - public @NonNull ListIterator listIterator(int index) { - ensureUnmodified(); - Objects.checkIndex(index, size + 1); - - return new ListIterator() { - int cursor = index; - int lastRet = -1; - final int expectedModCount = ReadOnlySubListFacade.this.modCount; - - public boolean hasNext() { - return cursor != ReadOnlySubListFacade.this.size; - } - - @SuppressWarnings("unchecked") - public E next() { - checkForComodification(); - int i = cursor; - if (i >= ReadOnlySubListFacade.this.size) - throw new NoSuchElementException(); - if (offset + i >= root.size()) - throw new ConcurrentModificationException(); - cursor = i + 1; - return root.get(offset + (lastRet = i)); - } - - public boolean hasPrevious() { - return cursor != 0; - } - - @SuppressWarnings("unchecked") - public E previous() { - checkForComodification(); - int i = cursor - 1; - if (i < 0) - throw new NoSuchElementException(); - if (offset + i >= root.size()) - throw new ConcurrentModificationException(); - cursor = i; - return root.get(offset + (lastRet = i)); - } - - public void forEachRemaining(Consumer action) { - Objects.requireNonNull(action); - final int size = ReadOnlySubListFacade.this.size; - int i = cursor; - if (i < size) { - if (offset + i >= root.size()) - throw new ConcurrentModificationException(); - for (; i < size && modCountSupplier.getAsInt() == expectedModCount; i++) - action.accept(get(offset + i)); - cursor = i; - lastRet = i - 1; - } - } - - public int nextIndex() { - return cursor; - } - - public int previousIndex() { - return cursor - 1; - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - - @Override - public void set(E e) { - throw new UnsupportedOperationException(); - } - - @Override - public void add(E e) { - throw new UnsupportedOperationException(); - } - - void checkForComodification() { - if (modCountSupplier.getAsInt() != expectedModCount) - throw new ConcurrentModificationException(); - } - }; - } - - public @NonNull ReadOnlyList readOnlySubList(int fromIndex, int toIndex) { - Objects.checkIndex(fromIndex, toIndex + 1); - Objects.checkIndex(toIndex, size + 1); - return new ReadOnlySubListFacade<>(this, fromIndex, toIndex); - } - - private void rangeCheckForAdd(int index) { - if (index < 0 || index > this.size) - throw new IndexOutOfBoundsException(outOfBoundsMsg(index)); - } - - private String outOfBoundsMsg(int index) { - return "Index: " + index + ", Size: " + this.size; - } - - private void ensureUnmodified() { - if (modCountSupplier.getAsInt() != modCount) - throw new ConcurrentModificationException(); - } - -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/SequencedCollectionFacade.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/SequencedCollectionFacade.java deleted file mode 100755 index 19c44ddd5..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/SequencedCollectionFacade.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * @(#)SequencedCollectionFacade.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.facade; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.readonly.ReadOnlyCollection; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedCollection; -import org.jhotdraw8.collection.sequenced.SequencedCollection; - -import java.util.Collection; -import java.util.Iterator; -import java.util.function.Consumer; -import java.util.function.IntSupplier; -import java.util.function.Predicate; -import java.util.function.Supplier; - -/** - * Wraps {@code Collection} functions into the {@link SequencedCollection} interface. - * - * @param the element type - * @author Werner Randelshofer - */ -public class SequencedCollectionFacade extends CollectionFacade implements SequencedCollection { - private final @NonNull Supplier getFirstFunction; - private final @NonNull Supplier getLastFunction; - - private final @NonNull Consumer addFirstFunction; - private final @NonNull Consumer addLastFunction; - private final @NonNull Supplier> reverseIteratorFunction; - - public SequencedCollectionFacade(@NonNull ReadOnlySequencedCollection backingCollection) { - this(backingCollection::iterator, () -> backingCollection.readOnlyReversed().iterator(), backingCollection::size, - backingCollection::contains, null, null, null, null, null, null); - } - - public SequencedCollectionFacade(@NonNull ReadOnlyCollection backingCollection, - @NonNull Supplier> reverseIteratorFunction) { - this(backingCollection::iterator, reverseIteratorFunction, backingCollection::size, - backingCollection::contains, null, null, null, null, null, null); - } - - public SequencedCollectionFacade(@NonNull Collection backingCollection, - @NonNull Supplier> reverseIteratorFunction) { - this(backingCollection::iterator, reverseIteratorFunction, backingCollection::size, - backingCollection::contains, backingCollection::clear, backingCollection::remove, - null, null, null, null); - } - - public SequencedCollectionFacade(@NonNull Supplier> iteratorFunction, - @NonNull Supplier> reverseIteratorFunction, - @NonNull IntSupplier sizeFunction, - @NonNull Predicate containsFunction) { - this(iteratorFunction, reverseIteratorFunction, sizeFunction, containsFunction, null, null, null, null, null, null); - } - - public SequencedCollectionFacade(@NonNull Supplier> iteratorFunction, - @NonNull Supplier> reverseIteratorFunction, - @NonNull IntSupplier sizeFunction, - @NonNull Predicate containsFunction, - @Nullable Runnable clearFunction, - @Nullable Predicate removeFunction, - @Nullable Supplier getFirstFunction, - @Nullable Supplier getLastFunction, - @Nullable Consumer addFirstFunction, - @Nullable Consumer addLastFunction) { - super(iteratorFunction, sizeFunction, containsFunction, clearFunction, removeFunction); - this.getFirstFunction = getFirstFunction == null ? () -> { - throw new UnsupportedOperationException(); - } : getFirstFunction; - this.getLastFunction = getLastFunction == null ? () -> { - throw new UnsupportedOperationException(); - } : getLastFunction; - this.addFirstFunction = addFirstFunction == null ? e -> { - throw new UnsupportedOperationException(); - } : addFirstFunction; - this.addLastFunction = addLastFunction == null ? e -> { - throw new UnsupportedOperationException(); - } : addLastFunction; - this.reverseIteratorFunction = reverseIteratorFunction; - } - - @Override - public void addFirst(E e) { - addFirstFunction.accept(e); - } - - @Override - public void addLast(E e) { - addLastFunction.accept(e); - } - - @Override - public E getFirst() { - return getFirstFunction.get(); - } - - @Override - public E getLast() { - return getLastFunction.get(); - } - - @Override - public @NonNull SequencedCollection _reversed() { - return new SequencedCollectionFacade<>( - reverseIteratorFunction, - iteratorFunction, - sizeFunction, - containsFunction, - clearFunction, - removeFunction, - getLastFunction, - getFirstFunction, - addLastFunction, - addFirstFunction); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/SequencedMapFacade.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/SequencedMapFacade.java deleted file mode 100644 index a636ae211..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/SequencedMapFacade.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * @(#)SequencedMapFacade.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.facade; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.mapped.MappedIterator; -import org.jhotdraw8.collection.mapped.MappedSpliterator; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedMap; -import org.jhotdraw8.collection.sequenced.SequencedCollection; -import org.jhotdraw8.collection.sequenced.SequencedMap; -import org.jhotdraw8.collection.sequenced.SequencedSet; - -import java.util.*; -import java.util.function.*; - -/** - * Wraps {@code Map} functions into the {@link SequencedMap} interface. - * - * @param the key type - * @param the value type - * @author Werner Randelshofer - */ -public class SequencedMapFacade extends MapFacade implements SequencedMap { - private final @NonNull Supplier> firstEntryFunction; - private final @NonNull Supplier> lastEntryFunction; - private final @NonNull BiFunction putFirstFunction; - private final @NonNull BiFunction putLastFunction; - private final @NonNull Supplier>> reverseIteratorFunction; - private final @NonNull Supplier>> reverseSpliteratorFunction; - - public SequencedMapFacade(@NonNull ReadOnlySequencedMap m) { - super(m); - this.firstEntryFunction = m::firstEntry; - this.lastEntryFunction = m::lastEntry; - this.putFirstFunction = (k, v) -> { - throw new UnsupportedOperationException(); - }; - this.putLastFunction = (k, v) -> { - throw new UnsupportedOperationException(); - }; - this.reverseIteratorFunction = () -> m.readOnlyReversed().iterator(); - this.reverseSpliteratorFunction = () -> m.readOnlyReversed().spliterator(); - } - - public SequencedMapFacade(@NonNull SequencedMap m) { - super(m); - this.firstEntryFunction = m::firstEntry; - this.lastEntryFunction = m::lastEntry; - this.putFirstFunction = m::putFirst; - this.putLastFunction = m::putLast; - this.reverseIteratorFunction = () -> m._reversed()._sequencedEntrySet().iterator(); - this.reverseSpliteratorFunction = () -> m._reversed()._sequencedEntrySet().spliterator(); - } - - public SequencedMapFacade( - @NonNull Supplier>> iteratorFunction, - @NonNull Supplier>> reverseIteratorFunction, - @NonNull IntSupplier sizeFunction, - @NonNull Predicate containsKeyFunction, - @NonNull Function getFunction, - @Nullable Runnable clearFunction, - @Nullable Function removeFunction, - @NonNull Supplier> firstEntryFunction, - @NonNull Supplier> lastEntryFunction, - @Nullable BiFunction putFunction, - @Nullable BiFunction putFirstFunction, - @Nullable BiFunction putLastFunction) { - this(iteratorFunction, - () -> Spliterators.spliterator(iteratorFunction.get(), sizeFunction.getAsInt(), Spliterator.DISTINCT), - reverseIteratorFunction, - () -> Spliterators.spliterator(reverseIteratorFunction.get(), sizeFunction.getAsInt(), Spliterator.DISTINCT), - sizeFunction, containsKeyFunction, - getFunction, clearFunction, removeFunction, firstEntryFunction, lastEntryFunction, - putFunction, putFirstFunction, putLastFunction); - } - - public SequencedMapFacade( - @NonNull Supplier>> iteratorFunction, - @NonNull Supplier>> spliteratorFunction, - @NonNull Supplier>> reverseIteratorFunction, - @NonNull Supplier>> reverseSpliteratorFunction, - @NonNull IntSupplier sizeFunction, - @NonNull Predicate containsKeyFunction, - @NonNull Function getFunction, - @Nullable Runnable clearFunction, - @Nullable Function removeFunction, - @NonNull Supplier> firstEntryFunction, - @NonNull Supplier> lastEntryFunction, - @Nullable BiFunction putFunction, - @Nullable BiFunction putFirstFunction, - @Nullable BiFunction putLastFunction) { - super(iteratorFunction, spliteratorFunction, sizeFunction, containsKeyFunction, getFunction, clearFunction, - removeFunction, putFunction); - this.firstEntryFunction = firstEntryFunction; - this.lastEntryFunction = lastEntryFunction; - this.putFirstFunction = putFirstFunction == null ? (k, v) -> { - throw new UnsupportedOperationException(); - } : putFirstFunction; - this.putLastFunction = putLastFunction == null ? (k, v) -> { - throw new UnsupportedOperationException(); - } : putLastFunction; - this.reverseIteratorFunction = reverseIteratorFunction; - this.reverseSpliteratorFunction = reverseSpliteratorFunction; - } - - @Override - public @NonNull SequencedSet> _sequencedEntrySet() { - return new SequencedSetFacade<>( - iteratorFunction, spliteratorFunction, - reverseIteratorFunction, reverseSpliteratorFunction, - sizeFunction, - this::containsEntry, - clearFunction, - this::removeEntry, - firstEntryFunction, - lastEntryFunction, null, null, null, null); - } - - @Override - public Entry firstEntry() { - return firstEntryFunction.get(); - } - - @Override - public @NonNull SequencedSet _sequencedKeySet() { - return new SequencedSetFacade<>( - () -> new MappedIterator<>(iteratorFunction.get(), Map.Entry::getKey), - () -> new MappedSpliterator<>(spliteratorFunction.get(), Map.Entry::getKey, Spliterator.DISTINCT | Spliterator.SIZED), - () -> new MappedIterator<>(reverseIteratorFunction.get(), Map.Entry::getKey), - () -> new MappedSpliterator<>(spliteratorFunction.get(), Map.Entry::getKey, Spliterator.DISTINCT | Spliterator.SIZED), - sizeFunction, - this::containsKey, - clearFunction, - this::removeEntry, - () -> { - Entry e = firstEntry(); - if (e == null) throw new NoSuchElementException(); - return e.getKey(); - }, - () -> { - Entry e = lastEntry(); - if (e == null) throw new NoSuchElementException(); - return e.getKey(); - }, - null, null, null, null); - } - - @Override - public Entry lastEntry() { - return lastEntryFunction.get(); - } - - @Override - public V putFirst(K k, V v) { - return putFirstFunction.apply(k, v); - } - - @Override - public V putLast(K k, V v) { - return putLastFunction.apply(k, v); - } - - @Override - public @NonNull SequencedMap _reversed() { - return new SequencedMapFacade<>( - reverseIteratorFunction, - iteratorFunction, - sizeFunction, - containsKeyFunction, - getFunction, - clearFunction, - removeFunction, - lastEntryFunction, - firstEntryFunction, - putFunction, - putLastFunction, - putFirstFunction - ); - } - - @Override - public @NonNull SequencedCollection _sequencedValues() { - return new SequencedCollectionFacade<>( - () -> new MappedIterator<>(iteratorFunction.get(), Map.Entry::getValue), - () -> new MappedIterator<>(reverseIteratorFunction.get(), Map.Entry::getValue), - sizeFunction, - this::containsKey, - clearFunction, - this::removeEntry, - () -> { - Entry entry = firstEntry(); - if (entry == null) { - throw new NoSuchElementException(); - } - return entry.getValue(); - }, - () -> { - Entry entry = lastEntry(); - if (entry == null) { - throw new NoSuchElementException(); - } - return entry.getValue(); - }, null, null - ); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/SequencedSetFacade.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/SequencedSetFacade.java deleted file mode 100755 index 09112d85e..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/SequencedSetFacade.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * @(#)SequencedSetFacade.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.facade; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.readonly.ReadOnlyCollection; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedCollection; -import org.jhotdraw8.collection.sequenced.SequencedSet; - -import java.util.Iterator; -import java.util.Set; -import java.util.Spliterator; -import java.util.Spliterators; -import java.util.function.Consumer; -import java.util.function.IntSupplier; -import java.util.function.Predicate; -import java.util.function.Supplier; - -/** - * Wraps {@code Set} functions into the {@link SequencedSet} interface. - * - * @param the element type - * @author Werner Randelshofer - */ -public class SequencedSetFacade extends SetFacade implements SequencedSet { - - private final @NonNull Supplier getFirstFunction; - private final @NonNull Supplier getLastFunction; - private final @NonNull Consumer addFirstFunction; - private final @NonNull Consumer addLastFunction; - private final @NonNull Supplier> reverseIteratorFunction; - private final @NonNull Supplier> reverseSpliteratorFunction; - private final @NonNull Predicate reversedAddFunction; - - public SequencedSetFacade(@NonNull ReadOnlyCollection backingSet, - @NonNull Supplier> reverseIteratorFunction) { - this(backingSet::iterator, backingSet::spliterator, - reverseIteratorFunction, - () -> Spliterators.spliterator(reverseIteratorFunction.get(), backingSet.size(), Spliterator.DISTINCT), - backingSet::size, - backingSet::contains, null, null, null, null, null, null, null, null); - } - - public SequencedSetFacade(@NonNull ReadOnlySequencedCollection backingSet) { - this(backingSet::iterator, backingSet::spliterator, () -> backingSet.readOnlyReversed().iterator(), - () -> backingSet.readOnlyReversed().spliterator(), backingSet::size, - backingSet::contains, null, null, null, null, null, null, null, null); - } - - public SequencedSetFacade(@NonNull Set backingSet, - @NonNull Supplier> reverseIteratorFunction) { - this(backingSet::iterator, backingSet::spliterator, - reverseIteratorFunction, () -> Spliterators.spliterator(reverseIteratorFunction.get(), backingSet.size(), Spliterator.DISTINCT), backingSet::size, - backingSet::contains, backingSet::clear, backingSet::remove, null, null, null, null, null, null); - } - - public SequencedSetFacade(@NonNull Supplier> iteratorFunction, - @NonNull Supplier> reverseIteratorFunction, - @NonNull IntSupplier sizeFunction, - @NonNull Predicate containsFunction) { - this(iteratorFunction, - () -> Spliterators.spliterator(iteratorFunction.get(), sizeFunction.getAsInt(), Spliterator.DISTINCT), reverseIteratorFunction, - () -> Spliterators.spliterator(reverseIteratorFunction.get(), sizeFunction.getAsInt(), Spliterator.DISTINCT), - sizeFunction, containsFunction, null, null, null, null, null, null, null, null); - } - - public SequencedSetFacade(@NonNull Supplier> iteratorFunction, - @NonNull Supplier> spliteratorFunction, - @NonNull Supplier> reverseIteratorFunction, - @NonNull Supplier> reverseSpliteratorFunction, - @NonNull IntSupplier sizeFunction, - @NonNull Predicate containsFunction, - @Nullable Runnable clearFunction, - @Nullable Predicate removeFunction, - @Nullable Supplier getFirstFunction, - @Nullable Supplier getLastFunction, - @Nullable Predicate addFunction, - @Nullable Predicate reversedAddFunction, - @Nullable Consumer addFirstFunction, - @Nullable Consumer addLastFunction) { - super(iteratorFunction, spliteratorFunction, sizeFunction, containsFunction, clearFunction, addFunction, removeFunction); - Supplier throwingSupplier = () -> { - throw new UnsupportedOperationException(); - }; - this.getFirstFunction = getFirstFunction == null ? throwingSupplier : getFirstFunction; - this.getLastFunction = getLastFunction == null ? throwingSupplier : getLastFunction; - Consumer throwingConsumer = e -> { - throw new UnsupportedOperationException(); - }; - Predicate throwingPredicate = e -> { - throw new UnsupportedOperationException(); - }; - this.addFirstFunction = addFirstFunction == null ? throwingConsumer : addFirstFunction; - this.addLastFunction = addLastFunction == null ? throwingConsumer : addLastFunction; - this.reversedAddFunction = reversedAddFunction == null ? throwingPredicate : reversedAddFunction; - this.reverseIteratorFunction = reverseIteratorFunction; - this.reverseSpliteratorFunction = reverseSpliteratorFunction; - } - - @Override - public void addFirst(E e) { - addFirstFunction.accept(e); - } - - @Override - public void addLast(E e) { - addLastFunction.accept(e); - } - - @Override - public E removeLast() { - E e = getLastFunction.get(); - removeFunction.test(e); - return e; - } - - @Override - public E getFirst() { - return getFirstFunction.get(); - } - - @Override - public E getLast() { - return getLastFunction.get(); - } - - @Override - public @NonNull SequencedSet _reversed() { - return new SequencedSetFacade<>( - reverseIteratorFunction, - reverseSpliteratorFunction, - iteratorFunction, - spliteratorFunction, - sizeFunction, - containsFunction, - clearFunction, - removeFunction, - getLastFunction, - getFirstFunction, - reversedAddFunction, - addFunction, - addLastFunction, - addFirstFunction); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/SetFacade.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/SetFacade.java deleted file mode 100755 index 474427088..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/SetFacade.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * @(#)SetFacade.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.facade; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.readonly.ReadOnlySet; - -import java.util.AbstractSet; -import java.util.Iterator; -import java.util.Set; -import java.util.Spliterator; -import java.util.Spliterators; -import java.util.function.IntSupplier; -import java.util.function.Predicate; -import java.util.function.Supplier; -import java.util.stream.Stream; - -/** - * Wraps {@code Set} functions into the {@link Set} interface. - * - * @param the element type - * @author Werner Randelshofer - */ -public class SetFacade extends AbstractSet implements ReadOnlySet { - protected final @NonNull Supplier> iteratorFunction; - protected final @NonNull Supplier> spliteratorFunction; - protected final @NonNull IntSupplier sizeFunction; - protected final @NonNull Predicate containsFunction; - protected final @NonNull Predicate addFunction; - protected final @NonNull Runnable clearFunction; - protected final @NonNull Predicate removeFunction; - - public SetFacade(@NonNull ReadOnlySet backingSet) { - this(backingSet::iterator, backingSet::spliterator, backingSet::size, - backingSet::contains, null, null, null); - } - - public SetFacade(@NonNull Set backingSet) { - this(backingSet::iterator, - backingSet::spliterator, - backingSet::size, - backingSet::contains, backingSet::clear, backingSet::add, backingSet::remove); - } - - public SetFacade(@NonNull Supplier> iteratorFunction, - @NonNull IntSupplier sizeFunction, - @NonNull Predicate containsFunction) { - this(iteratorFunction, - () -> Spliterators.spliterator(iteratorFunction.get(), sizeFunction.getAsInt(), Spliterator.DISTINCT), - sizeFunction, containsFunction, null, null, null); - } - - public SetFacade(@NonNull Supplier> iteratorFunction, - @NonNull Supplier> spliteratorFunction, - @NonNull IntSupplier sizeFunction, - @NonNull Predicate containsFunction, - @Nullable Runnable clearFunction, - @Nullable Predicate addFunction, - @Nullable Predicate removeFunction) { - this.iteratorFunction = iteratorFunction; - this.spliteratorFunction = spliteratorFunction; - this.sizeFunction = sizeFunction; - this.containsFunction = containsFunction; - this.clearFunction = clearFunction == null ? () -> { - throw new UnsupportedOperationException(); - } : clearFunction; - this.removeFunction = removeFunction == null ? o -> { - throw new UnsupportedOperationException(); - } : removeFunction; - this.addFunction = addFunction == null ? o -> { - throw new UnsupportedOperationException(); - } : addFunction; - } - - @Override - public boolean remove(Object o) { - return removeFunction.test(o); - } - - @Override - public void clear() { - clearFunction.run(); - } - - @SuppressWarnings("unchecked") - @Override - public Spliterator spliterator() { - return spliteratorFunction.get(); - } - - @Override - public Stream stream() { - return super.stream(); - } - - @Override - public @NonNull Iterator iterator() { - return iteratorFunction.get(); - } - - @Override - public boolean equals(Object o) { - return super.equals(o); - } - - @Override - public int size() { - return sizeFunction.getAsInt(); - } - - @Override - public boolean contains(Object o) { - return containsFunction.test(o); - } - - @Override - public boolean add(E e) { - return addFunction.test(e); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/package-info.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/package-info.java deleted file mode 100755 index df82b47d2..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/* - * @(#)package-info.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -/** - * Provides facades for collection interfaces. - */ -package org.jhotdraw8.collection.facade; diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableAddOnlySet.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableAddOnlySet.java deleted file mode 100644 index cb93d3d91..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableAddOnlySet.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * @(#)ImmutableAddOnlySet.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.immutable; - -import org.jhotdraw8.annotation.NonNull; - -/** - * Functional Interface for an immutable set that only provides an - * {@link #add add} method. - * - * @param the element type - */ -public interface ImmutableAddOnlySet { - /** - * Returns a copy of this set that contains all elements - * of this set and also the specified element. - * - * @param element an element - * @return this set if it already contains the element, or - * a different set with the element added - */ - @NonNull ImmutableAddOnlySet add(@NonNull E element); - -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableCollection.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableCollection.java deleted file mode 100755 index 265dda303..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableCollection.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * @(#)ImmutableCollection.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.immutable; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.readonly.ReadOnlyCollection; -import org.jhotdraw8.collection.transform.Transformable; - -import java.util.Collection; - -/** - * Interface for an immutable collection; the implementation - * guarantees that the state of the collection does not change. - * - * @param the element type - */ -public interface ImmutableCollection extends ReadOnlyCollection, Transformable { - /** - * Returns a copy of this collection that is empty. - * - * @return this collection instance if it is already empty, or a different collection - * instance that is empty. - */ - @NonNull ImmutableCollection clear(); - - /** - * Returns a copy of this collection that contains all elements - * of this collection and also the specified element. - *

- * A collection may prevent that the same element can be - * added more than once. - * - * @param element an element - * @return this collection instance if it already contains the element, or - * a different collection instance with the element added - */ - @NonNull ImmutableCollection add(E element); - - /** - * Returns a copy of this collection that contains all elements - * of this collection and also all elements of the specified - * collection. - *

- * A collection may prevent that the same element can be - * added more than once. - * - * @param c a collection to be added to this collection - * @return this collection instance if it already contains the elements, or - * a different collection instance with the elements added - */ - @SuppressWarnings("unchecked") - @NonNull ImmutableCollection addAll(@NonNull Iterable c); - - /** - * Returns a copy of this collection that contains all elements - * of this collection except the specified element. - * - * @param element an element - * @return this collection instance if it already does not contain the element, or - * a different collection instance with the element removed - */ - @NonNull ImmutableCollection remove(E element); - - /** - * Returns a copy of this collection that contains all elements - * of this collection except the elements of the specified - * collection. - * - * @param c a collection with elements to be removed from this collection - * @return this collection instance if it already does not contain the elements, or - * a different collection instance with the elements removed - */ - @SuppressWarnings("unchecked") - @NonNull ImmutableCollection removeAll(@NonNull Iterable c); - - /** - * Returns a copy of this collection that contains only elements - * that are in this collection and in the specified collection. - * - * @param c a collection with elements to be retained in this collection - * @return this collection instance if it has not changed, or - * a different collection instance with elements removed - */ - @SuppressWarnings("unchecked") - @NonNull ImmutableCollection retainAll(@NonNull Iterable c); - - - /** - * Returns a mutable copy of this collection. - * - * @return a mutable copy. - */ - @NonNull Collection toMutable(); -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableList.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableList.java deleted file mode 100644 index 21413cefc..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableList.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * @(#)ImmutableList.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.immutable; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.readonly.ReadOnlyList; - -import java.util.List; - -/** - * Interface for an immutable list; the implementation guarantees that the state of the collection does not change. - *

- * An immutable list provides methods for creating a new immutable list with - * added or removed elements, without changing the original immutable list. - * - * @param the element type - */ -public interface ImmutableList extends ReadOnlyList, ImmutableSequencedCollection { - /** - * Returns a copy of this list that is empty. - * - * @return this list instance if it is already empty, or a different list - * instance that is empty. - */ - @Override - @NonNull ImmutableList clear(); - - @Override - @NonNull ImmutableList addFirst(@Nullable final E element); - - @Override - @NonNull ImmutableList addLast(@Nullable final E element); - - @Override - default ImmutableList removeFirst() { - return (ImmutableList) ImmutableSequencedCollection.super.removeFirst(); - } - - @Override - default ImmutableList removeLast() { - return (ImmutableList) ImmutableSequencedCollection.super.removeLast(); - } - - /** - * Returns a copy of this list that contains all elements - * of this list and the specified element appended to the - * end of the list. - * - * @param element an element - * @return a different list instance with the element added - */ - @Override - @NonNull ImmutableList add(@NonNull E element); - - /** - * Returns a copy of this list that contains all elements - * of this list and the specified element appended to the - * end of the list. - * - * @param index the insertion index - * @param element an element - * @return a different list instance with the element added - */ - @NonNull ImmutableList add(int index, @NonNull E element); - - /** - * Returns a copy of this list that contains all elements - * of this list and all elements of the specified - * collection appended. - * - * @param c a collection to be added to this list - * @return a different list instance with the elements added - */ - @Override - @NonNull ImmutableList addAll(@NonNull Iterable c); - - /** - * Returns a copy of this list that contains all elements - * of this list and all elements of the specified - * collection appended. - * - * @param index the insertion index - * @param c a collection to be added to this list - * @return a different list instance with the elements added - */ - @NonNull ImmutableList addAll(int index, @NonNull Iterable c); - - /** - * Returns a copy of this list that contains all elements - * of this list except the specified element. - * - * @param element an element - * @return this list instance if it already does not contain the element, or - * a different list instance with the element removed - */ - @Override - @NonNull ImmutableList remove(@NonNull E element); - - /** - * Returns a copy of this list that contains all elements - * of this list except the element at the specified index - * - * @param index an index - * @return a different list instance with the element removed - */ - @NonNull ImmutableList removeAt(int index); - - /** - * Returns a copy of this list that contains all elements - * of this list except the elements in the specified range. - * - * @param fromIndex from index (inclusive) of the sub-list - * @param toIndex to index (exclusive) of the sub-list - * @return a different list instance with the element removed - */ - @NonNull ImmutableList removeRange(int fromIndex, int toIndex); - - /** - * Returns a copy of this list that contains all elements - * of this list except the elements of the specified - * collection. - * - * @param c a collection with elements to be removed from this set - * @return this list instance if it already does not contain the elements, or - * a different list instance with the elements removed - */ - @Override - @NonNull ImmutableList removeAll(@NonNull Iterable c); - - /** - * Returns a copy of this list that contains only elements - * that are in this list and in the specified collection. - * - * @param c a collection with elements to be retained in this set - * @return this list instance if it has not changed, or - * a different list instance with elements removed - */ - @Override - @NonNull ImmutableList retainAll(@NonNull Iterable c); - - /** - * Returns a reversed copy of this list. - *

- * This operation may be implemented in O(N). - *

- * Use {@link #readOnlyReversed()} if you only - * need to iterate in the reversed sequence over this list. - * - * @return a reversed copy of this list. - */ - @NonNull VectorList reversed(); - - /** - * Returns a copy of this list that contains all elements - * of this list and the specified element replaced. - * - * @param element an element - * @return this list instance if it has not changed, or - * a different list instance with the element changed - */ - @NonNull ImmutableList set(int index, @NonNull E element); - - /** - * Returns a copy of this list that contains only - * the elements in the given index range. - * - * @param fromIndex from index (inclusive) of the sub-list - * @param toIndex to index (exclusive) of the sub-list - * @return this list instance if it has not changed, or - * a different list instance with the element changed - */ - @Override - @NonNull ImmutableList readOnlySubList(int fromIndex, int toIndex); - - /** - * Returns a mutable copy of this list. - * - * @return a mutable copy. - */ - @NonNull List toMutable(); -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableMap.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableMap.java deleted file mode 100644 index 98a53fdaa..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableMap.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * @(#)ImmutableMap.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.immutable; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.readonly.ReadOnlyCollection; -import org.jhotdraw8.collection.readonly.ReadOnlyMap; -import org.jhotdraw8.collection.transform.Transformable; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Map; - -/** - * Interface for an immutable map; the implementation guarantees that the state - * of the map does not change. - *

- * An immutable map provides methods for creating a new immutable map with - * new, updated or deleted entries, without changing the original immutable map. - * - * @param the key type - * @param the value type - */ -public interface ImmutableMap extends ReadOnlyMap, Transformable { - - /** - * Returns a copy of this map that is empty. - * - * @return this set instance if it is already empty, or a different set - * instance that is empty. - */ - @NonNull ImmutableMap clear(); - - /** - * Returns a copy of this map that contains all entries - * of this map with the specified entry added or updated. - * - * @param key the key of the entry - * @param value the value of the entry - * @return this map instance if it already contains the same entry, or - * a different map instance with the entry added or updated - */ - @NonNull ImmutableMap put(@NonNull K key, @Nullable V value); - - /** - * Returns a copy of this map that contains all entries - * of this map with entries from the specified map added or updated. - * - * @param m another map - * @return this map instance if it already contains the same entries, or - * a different map instance with the entries added or updated - */ - default @NonNull ImmutableMap putAll(@NonNull Map m) { - return putAll(m.entrySet()); - } - - /** - * Returns a copy of this map that contains all entries - * of this map with entries from the specified map added or updated. - * - * @param c another map - * @return this map instance if it already contains the same entries, or - * a different map instance with the entries added or updated - */ - @SuppressWarnings("unchecked") - default @NonNull ImmutableMap putAll(@NonNull Iterable> c) { - if (c instanceof Collection co && co.isEmpty() - || c instanceof ReadOnlyCollection rc && rc.isEmpty()) { - return this; - } - if (isEmpty() && c.getClass() == this.getClass()) { - return (ImmutableMap) c; - } - var s = this; - for (var e : c) { - s = s.put(e.getKey(), e.getValue()); - } - return s; - } - - /** - * Returns a copy of this map that contains all entries - * of this map with entries from the specified map added or updated. - * - * @param kv a list of alternating keys and values - * @return this map instance if it already contains the same entries, or - * a different map instance with the entries added or updated - */ - @SuppressWarnings("unchecked") - default @NonNull ImmutableMap putKeyValues(@NonNull Object @NonNull ... kv) { - ImmutableMap that = this; - for (int i = 0; i < kv.length; i += 2) { - that = that.put((K) kv[i], (V) kv[i + 1]); - } - return that; - } - - - /** - * Returns a copy of this map that contains all entries - * of this map with the specified entry removed. - * - * @param key the key of the entry - * @return this map instance if it already does not contain the entry, or - * a different map instance with the entry removed - */ - @NonNull ImmutableMap remove(@NonNull K key); - - /** - * Returns a copy of this map that contains all entries - * of this map except the entries of the specified - * collection. - * - * @param c a collection with keys of entries to be removed from this map - * @return this map instance if it already does not contain the entries, or - * a different map instance with the entries removed - */ - default @NonNull ImmutableMap removeAll(@NonNull Iterable c) { - if (isEmpty() - || c instanceof Collection co && co.isEmpty() - || c instanceof ReadOnlyCollection rc && rc.isEmpty()) { - return this; - } - var s = this; - for (var k : c) { - s = s.remove(k); - } - return s; - } - - /** - * Returns a copy of this map that contains only entries - * that are in this map and in the specified collection. - * - * @param c a collection with keys of entries to be retained in this map - * @return this map instance if it has not changed, or - * a different map instance with entries removed - */ - @SuppressWarnings("unchecked") - default @NonNull ImmutableMap retainAll(@NonNull Iterable c) { - if (isEmpty() - || c instanceof Collection co && co.isEmpty() - || c instanceof ReadOnlyCollection rc && rc.isEmpty()) { - return this; - } - if (c instanceof ReadOnlyCollection co) { - if (co.isEmpty()) { - return clear(); - } - var s = this; - for (var e : this) { - if (!co.contains(e)) { - s = s.remove((K) e); - } - } - return s; - } - if (!(c instanceof Collection)) { - HashSet hm = new HashSet<>(); - c.forEach(hm::add); - c = hm; - } - var cc = (Collection) c; - if (cc.isEmpty()) { - return clear(); - } - var s = this; - for (var e : this) { - if (!cc.contains(e)) { - s = s.remove((K) e); - } - } - return s; - } - - /** - * Returns a copy of this map that contains only entries - * that are in this map and in the specified collection. - * - * @param c a collection with keys of entries to be retained in this map - * @return this map instance if it has not changed, or - * a different map instance with entries removed - */ - default @NonNull ImmutableMap retainAll(@NonNull ReadOnlyCollection c) { - return retainAll(c.asCollection()); - } - - /** - * Returns a mutable copy of this map. - * - * @return a mutable copy. - */ - @NonNull Map toMutable(); - -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableSequencedCollection.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableSequencedCollection.java deleted file mode 100644 index 01e4d77bd..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableSequencedCollection.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * @(#)ImmutableSequencedSet.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.immutable; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedCollection; - -import java.util.NoSuchElementException; - -/** - * Interface for an immutable collection with a well-defined iteration order; - * the implementation guarantees that the state of the collection does not - * change. - *

- * An immutable sequenced collection provides methods for creating a new - * immutable sequenced collection with added or removed elements, without - * changing the original immutable sequenced collection. - * - * @param the element type - */ -public interface ImmutableSequencedCollection extends ImmutableCollection, ReadOnlySequencedCollection { - @Override - @NonNull ImmutableSequencedCollection add(E element); - - @Override - @NonNull ImmutableSequencedCollection addAll(@NonNull Iterable c); - - /** - * Returns a copy of this collection that contains all elements - * of this collection and also the specified element as the first - * element in the iteration order. - *

- * A collection may prevent that the same element can be - * added more than once. - *

- * If the iteration order is based on an ordering relation of - * the elements, then the element is only the first in a sequence of elements - * with the same ordering relation; which is not necessarily the first in - * the total iteration order. - * - * @param element an element - * @return this collection instance if it already contains the element - * as the first in the iteration order, or - * a different collection instance with the element added as the first - * in the iteration order - */ - @NonNull ImmutableSequencedCollection addFirst(final @Nullable E element); - - /** - * Returns a copy of this collection that contains all elements - * of this collection and also the specified element as the last - * element in the iteration order. - *

- * A collection may prevent that the same element can be - * added more than once. - *

- * If the iteration order is based on an ordering relation of - * the elements, then the element is only the last in a sequence of elements - * with the same ordering relation; which is not necessarily the last in - * the total iteration order. - * - * @param element an element - * @return this collection instance if it already contains the element - * as the last in the iteration order, or - * a different collection instance with the element added as the last - * in the iteration order - */ - @NonNull ImmutableSequencedCollection addLast(final @Nullable E element); - - @Override - @NonNull ImmutableSequencedCollection clear(); - - @Override - @NonNull ImmutableSequencedCollection remove(E element); - - @Override - @NonNull ImmutableSequencedCollection removeAll(@NonNull Iterable c); - - /** - * Returns a copy of this set that contains all elements - * of this set except the first. - * - * @return a new set instance with the first element removed - * @throws NoSuchElementException if this set is empty - */ - default ImmutableSequencedCollection removeFirst() { - return remove(getFirst()); - } - - /** - * Returns a copy of this set that contains all elements - * of this set except the last. - * - * @return a new set instance with the last element removed - * @throws NoSuchElementException if this set is empty - */ - default ImmutableSequencedCollection removeLast() { - return remove(getLast()); - } - - @Override - @NonNull ImmutableSequencedCollection retainAll(@NonNull Iterable c); - -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableSequencedMap.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableSequencedMap.java deleted file mode 100644 index 085f3583f..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableSequencedMap.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * @(#)ImmutableSequencedMap.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.immutable; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedMap; - -import java.util.Map; -import java.util.NoSuchElementException; - -/** - * Interface for an immutable map with a well-defined iteration order; the - * implementation guarantees that the state of the collection does not change. - *

- * An immutable sequenced map provides methods for creating a new immutable sequenced map with - * added, updated or removed entries, without changing the original immutable sequenced map. - * - * @param the key type - * @param the value type - */ -public interface ImmutableSequencedMap extends ImmutableMap, ReadOnlySequencedMap { - @Override - @NonNull ImmutableSequencedMap clear(); - - @Override - @NonNull ImmutableSequencedMap put(@NonNull K key, @Nullable V value); - - /** - * Creates an entry for the specified key and value and adds it to the front - * of the map if an entry for the specified key is not already present. - * If this map already contains an entry for the specified key, replaces the - * value and moves the entry to the front. - * - * @param key the key - * @param value the value - * @return this map instance if no changes are needed, or a different map - * instance with the applied changes. - */ - @NonNull ImmutableSequencedMap putFirst(@NonNull K key, @Nullable V value); - - /** - * Creates an entry for the specified key and value and adds it to the end - * of the map if an entry for the specified key is not already present. - * If this map already contains an entry for the specified key, replaces the - * value and moves the entry to the end. - * - * @param key the key - * @param value the value - * @return this map instance if no changes are needed, or a different map - * instance with the applied changes. - */ - @NonNull ImmutableSequencedMap putLast(@NonNull K key, @Nullable V value); - - - @Override - @NonNull ImmutableSequencedMap putAll(@NonNull Iterable> c); - - @Override - @NonNull - default ImmutableSequencedMap putKeyValues(@NonNull Object @NonNull ... kv) { - return (ImmutableSequencedMap) ImmutableMap.super.putKeyValues(kv); - } - - @Override - @NonNull ImmutableSequencedMap remove(@NonNull K key); - - @Override - @NonNull ImmutableSequencedMap removeAll(@NonNull Iterable c); - - /** - * Returns a copy of this map that contains all entries - * of this map except the first. - * - * @return a new map instance with the first element removed - * @throws NoSuchElementException if this map is empty - */ - default @NonNull ImmutableSequencedMap removeFirst() { - Map.Entry e = firstEntry(); - return e == null ? this : remove(e.getKey()); - } - - /** - * Returns a copy of this map that contains all entries - * of this map except the last. - * - * @return a new map instance with the last element removed - * @throws NoSuchElementException if this set is empty - */ - default @NonNull ImmutableSequencedMap removeLast() { - Map.Entry e = lastEntry(); - return e == null ? this : remove(e.getKey()); - } - - @Override - @NonNull ImmutableSequencedMap retainAll(@NonNull Iterable c); - - @Override - @NonNull Map toMutable(); -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableSequencedSet.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableSequencedSet.java deleted file mode 100644 index a8f4946da..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableSequencedSet.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * @(#)ImmutableSequencedSet.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.immutable; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedSet; -import org.jhotdraw8.collection.sequenced.SequencedSet; - -import java.util.NoSuchElementException; - -/** - * Interface for an immutable set with a well-defined iteration order; the - * implementation guarantees that the state of the collection does not change. - *

- * An immutable sequenced set provides methods for creating a new immutable sequenced set with - * added or removed elements, without changing the original immutable sequenced set. - * - * @param the element type - */ -public interface ImmutableSequencedSet extends ImmutableSet, ReadOnlySequencedSet, ImmutableSequencedCollection { - @Override - @NonNull ImmutableSequencedSet add(E element); - - @Override - default @NonNull ImmutableSequencedSet addAll(@NonNull Iterable c) { - return (ImmutableSequencedSet) ImmutableSet.super.addAll(c); - } - - @Override - @NonNull ImmutableSequencedSet addFirst(final @Nullable E element); - - @Override - @NonNull ImmutableSequencedSet addLast(final @Nullable E element); - - @Override - @NonNull ImmutableSequencedSet clear(); - - @Override - @NonNull ImmutableSequencedSet remove(E element); - - @Override - default @NonNull ImmutableSequencedSet removeAll(@NonNull Iterable c) { - return (ImmutableSequencedSet) ImmutableSet.super.removeAll(c); - } - - /** - * Returns a copy of this set that contains all elements - * of this set except the first. - * - * @return a new set instance with the first element removed - * @throws NoSuchElementException if this set is empty - */ - @Override - default ImmutableSequencedSet removeFirst() { - return remove(getFirst()); - } - - /** - * Returns a copy of this set that contains all elements - * of this set except the last. - * - * @return a new set instance with the last element removed - * @throws NoSuchElementException if this set is empty - */ - @Override - default ImmutableSequencedSet removeLast() { - return remove(getLast()); - } - - @Override - default @NonNull ImmutableSequencedSet retainAll(@NonNull Iterable c) { - return (ImmutableSequencedSet) ImmutableSet.super.retainAll(c); - } - - @Override - @NonNull SequencedSet toMutable(); -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableSet.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableSet.java deleted file mode 100644 index e5ec029ee..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ImmutableSet.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * @(#)ImmutableSet.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.immutable; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.readonly.ReadOnlyCollection; -import org.jhotdraw8.collection.readonly.ReadOnlySet; - -import java.util.Collection; -import java.util.Set; - -/** - * Interface for an immutable set; the implementation guarantees that the - * state of the collection does not change. - *

- * An immutable set provides methods for creating a new immutable set with - * added or removed elements, without changing the original immutable set. - * - * @param the element type - */ -public interface ImmutableSet extends ReadOnlySet, ImmutableCollection { - /** - * Returns a copy of this set that is empty. - * - * @return this set instance if it is already empty, or a different set - * instance that is empty. - */ - @NonNull ImmutableSet clear(); - - /** - * Returns a copy of this set that contains all elements - * of this set and also the specified element. - * - * @param element an element - * @return this set instance if it already contains the element, or - * a different set instance with the element added - */ - @NonNull ImmutableSet add(E element); - - /** - * Returns a copy of this set that contains all elements - * of this set and also all elements of the specified - * collection. - * - * @param c a collection to be added to this set - * @return this set instance if it already contains the elements, or - * a different set instance with the elements added - */ - @SuppressWarnings("unchecked") - default @NonNull ImmutableSet addAll(@NonNull Iterable c) { - if (c instanceof Collection co && co.isEmpty() - || c instanceof ReadOnlyCollection rc && rc.isEmpty()) { - return this; - } - if (isEmpty() && c.getClass() == this.getClass()) { - return (ImmutableSet) c; - } - var s = this; - for (var e : c) { - s = s.add(e); - } - return s; - } - - /** - * Returns a copy of this set that contains all elements - * of this set except the specified element. - * - * @param element an element - * @return this set instance if it already does not contain the element, or - * a different set instance with the element removed - */ - @NonNull ImmutableSet remove(E element); - - /** - * Returns a copy of this set that contains all elements - * of this set except the elements of the specified - * collection. - * - * @param c a collection with elements to be removed from this set - * @return this set instance if it already does not contain the elements, or - * a different set instance with the elements removed - */ - @SuppressWarnings("unchecked") - default @NonNull ImmutableSet removeAll(@NonNull Iterable c) { - if (isEmpty() - || c instanceof Collection co && co.isEmpty() - || c instanceof ReadOnlyCollection rc && rc.isEmpty()) { - return this; - } - var s = this; - for (var e : c) { - s = s.remove((E) e); - } - return s; - } - - /** - * Returns a copy of this set that contains only elements - * that are in this set and in the specified collection. - * - * @param c a collection with elements to be retained in this set - * @return this set instance if it has not changed, or - * a different set instance with elements removed - */ - @SuppressWarnings("unchecked") - default @NonNull ImmutableSet retainAll(@NonNull Iterable c) { - if (isEmpty() - || c instanceof Collection co && co.isEmpty() - || c instanceof ReadOnlyCollection rc && rc.isEmpty()) { - return this; - } - if (c instanceof Collection co) { - var s = this; - for (var e : this) { - if (!co.contains(e)) { - s = s.remove(e); - } - } - return s; - } - if (!(c instanceof ReadOnlyCollection rc)) { - ImmutableSet clear = (ImmutableSet) clear(); - c = clear.addAll(c); - } - var rc = (ReadOnlyCollection) c; - var s = this; - for (var e : this) { - if (!rc.contains(e)) { - s = s.remove(e); - } - } - return s; - } - - - /** - * Returns a mutable copy of this set. - * - * @return a mutable copy. - */ - @NonNull Set toMutable(); - -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ZipTransformer.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ZipTransformer.java deleted file mode 100644 index 32470a3c8..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ZipTransformer.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.jhotdraw8.collection.immutable; - -import java.util.Iterator; -import java.util.function.BiFunction; -import java.util.function.Function; - -/** - * Provides 'zip' transformations. - */ -public class ZipTransformer { - /** - * Zips a list with itself. - *

- * Example: - *

{@literal
-     * VectorList list = VectorList.of("a","b","c");
-     * VectorList result = list.transformed().by(Zipper.zipList((a,b)->a+b));
-     * // result = ["ab","c"];
-     * }
- * - * @param combinator the combinator - * @param the element type - * @param the list type - * @return the zipped list - */ - @SuppressWarnings("unchecked") - public static > Function zipList(BiFunction combinator) { - return c -> { - var result = c.clear(); - Iterator i = c.iterator(); - while (i.hasNext()) { - E a = i.next(); - if (i.hasNext()) { - E b = i.next(); - result = result.add(combinator.apply(a, b)); - } else { - result = result.add(a); - } - } - return (T) result; - }; - } - - /** - * Zips a list with itself in reverse order. - *

- * Example: - *

{@literal
-     * VectorList list = VectorList.of("a","b","c");
-     * VectorList result = list.transformed().by(Zipper.zipListInReverse((a,b)->a+b));
-     * // result = ["a","bc"];
-     * }
- * - * @param combinator the combinator - * @param the element type - * @param the list type - * @return the zipped list - */ - @SuppressWarnings("unchecked") - public static > Function zipListInReverse(BiFunction combinator) { - return c -> { - var result = c.clear(); - Iterator i = c.reversed().iterator(); - while (i.hasNext()) { - E a = i.next(); - if (i.hasNext()) { - E b = i.next(); - result = result.addFirst(combinator.apply(b, a)); - } else { - result = result.addFirst(a); - } - } - return (T) result; - }; - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/package-info.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/package-info.java deleted file mode 100755 index c565e74cc..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/package-info.java +++ /dev/null @@ -1,9 +0,0 @@ -/* - * @(#)package-info.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -/** - * Defines interfaces for immutable collections. - */ -package org.jhotdraw8.collection.immutable; diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/IdentityObject.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/IdentityObject.java deleted file mode 100644 index 5da8f4d92..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/IdentityObject.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * @(#)IdentityObject.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.impl; - -import java.io.Serial; -import java.io.Serializable; - -/** - * An object with a unique identity within this VM. - */ -public class IdentityObject implements Serializable { - @Serial - private static final long serialVersionUID = 0L; - - public IdentityObject() { - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/AbstractMutableChampMap.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/AbstractMutableChampMap.java deleted file mode 100644 index 09e3865d6..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/AbstractMutableChampMap.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * @(#)AbstractChampMap.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.impl.champ; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.impl.IdentityObject; -import org.jhotdraw8.collection.readonly.ReadOnlyCollection; -import org.jhotdraw8.collection.readonly.ReadOnlyMap; - -import java.io.Serial; -import java.io.Serializable; -import java.util.*; -import java.util.function.Predicate; - -/** - * Abstract base class for CHAMP maps. - * - * @param the key type of the map - * @param the value typeof the map - * @param the data type of the CHAMP trie - */ -public abstract class AbstractMutableChampMap extends AbstractMap implements Serializable, Cloneable, - ReadOnlyMap { - @Serial - private static final long serialVersionUID = 0L; - - /** - * The current owner id of this map. - *

- * All nodes that have the same non-null owner id, are exclusively owned - * by this map, and therefore can be mutated without affecting other map. - *

- * If this owner id is null, then this map does not own any nodes. - */ - @Nullable - protected IdentityObject owner; - - /** - * The root of this CHAMP trie. - */ - protected BitmapIndexedNode root; - - /** - * The number of entries in this map. - */ - protected int size; - - /** - * The number of times this map has been structurally modified. - */ - protected int modCount; - - /** - * Gets the owner object. If the owner object was set to null, creates a new one. - * - * @return the owner object - */ - @NonNull - protected IdentityObject getOrCreateOwner() { - if (owner == null) { - owner = new IdentityObject(); - } - return owner; - } - - @Override - @SuppressWarnings("unchecked") - public @NonNull AbstractMutableChampMap clone() { - try { - owner = null; - return (AbstractMutableChampMap) super.clone(); - } catch (CloneNotSupportedException e) { - throw new InternalError(e); - } - } - - @Override - public int size() { - return size; - } - - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof AbstractMutableChampMap) { - AbstractMutableChampMap that = (AbstractMutableChampMap) o; - return size == that.size && root.equivalent(that.root); - } - return super.equals(o); - } - - @Override - public V getOrDefault(@NonNull Object key, V defaultValue) { - return super.getOrDefault(key, defaultValue); - } - - /** - * Returns the current value of the modification counter. - * - * @return value of modification counter - */ - protected int getModCount() { - return modCount; - } - - /** - * Adds all specified elements that are not already in this set. - * - * @param c an iterable of elements - * @return {@code true} if this set changed - */ - public boolean putAll(@NonNull Iterable> c) { - if (c == this) { - return false; - } - boolean modified = false; - for (var e : c) { - var oldValue = put(e.getKey(), e.getValue()); - modified = modified || !Objects.equals(oldValue, e); - } - return modified; - } - - /** - * Removes all specified entries that are in this set. - * - * @param c an iterable of keys - * @return {@code true} if this map changed - */ - public boolean removeAll(@NonNull Iterable c) { - if (isEmpty()) { - return false; - } - boolean modified = false; - for (Object o : c) { - if (containsKey(o)) { - remove(o); - modified = true; - } - } - return modified; - } - - /** - * Retains all specified entries that are in this set. - * - * @param c an iterable of keys - * @return {@code true} if this map changed - */ - public boolean retainAll(@NonNull Iterable c) { - if (isEmpty()) { - return false; - } - if ((c instanceof Collection cc && cc.isEmpty()) - || (c instanceof ReadOnlyCollection rc) && rc.isEmpty()) { - clear(); - return true; - } - Predicate predicate; - if (c instanceof Collection that) { - predicate = that::contains; - } else if (c instanceof ReadOnlyCollection that) { - predicate = that::contains; - } else { - HashSet that = new HashSet<>(); - c.forEach(that::add); - predicate = that::contains; - } - boolean removed = false; - for (Iterator> i = iterator(); i.hasNext(); ) { - var e = i.next(); - if (!predicate.test(e.getKey())) { - i.remove(); - removed = true; - } - } - return removed; - } - - /** - * Removes the specified entry frm the map. - * - * @param o an entry (should be a {@link Map.Entry}). - * @return true if the element was contained in the map - */ - @SuppressWarnings("unchecked") - protected boolean removeEntry(@Nullable Object o) { - if (containsEntry(o)) { - assert o != null; - remove(((Entry) o).getKey()); - return true; - } - return false; - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/AbstractMutableChampSet.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/AbstractMutableChampSet.java deleted file mode 100644 index acd7d53e9..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/AbstractMutableChampSet.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * @(#)AbstractMutableChampSet.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.impl.champ; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.impl.IdentityObject; -import org.jhotdraw8.collection.readonly.ReadOnlyCollection; -import org.jhotdraw8.collection.readonly.ReadOnlySet; - -import java.io.Serial; -import java.io.Serializable; -import java.util.AbstractSet; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.function.Predicate; -import java.util.stream.Stream; - -/** - * Abstract base class for CHAMP sets. - * - * @param the element type of the set - * @param the data type of the CHAMP trie - */ -public abstract class AbstractMutableChampSet extends AbstractSet implements Serializable, Cloneable, - ReadOnlySet { - @Serial - private static final long serialVersionUID = 0L; - - /** - * The current owner id of this set. - *

- * All nodes that have the same non-null owner id, are exclusively owned - * by this set, and therefore can be mutated without affecting other sets. - *

- * If this owner id is null, then this set does not own any nodes. - */ - protected @Nullable IdentityObject owner; - - /** - * The root of this CHAMP trie. - */ - protected BitmapIndexedNode root; - - /** - * The number of elements in this set. - */ - protected int size; - - /** - * The number of times this set has been structurally modified. - */ - protected transient int modCount; - - @Override - public boolean addAll(@NonNull Collection c) { - return addAll((Iterable) c); - } - - /** - * Adds all specified elements that are not already in this set. - * - * @param c an iterable of elements - * @return {@code true} if this set changed - */ - @SuppressWarnings("unchecked") - public boolean addAll(@NonNull Iterable c) { - boolean added = false; - for (E e : c) { - added |= add(e); - } - return added; - } - - /** - * Retains all specified elements that are in this set. - * - * @param c an iterable of elements - * @return {@code true} if this set changed - */ - public boolean retainAll(@NonNull Iterable c) { - if (c == this || isEmpty()) { - return false; - } - if ((c instanceof Collection cc && cc.isEmpty()) - || (c instanceof ReadOnlyCollection rc) && rc.isEmpty()) { - clear(); - return true; - } - Predicate predicate; - if (c instanceof Collection that) { - predicate = that::contains; - } else if (c instanceof ReadOnlyCollection that) { - predicate = that::contains; - } else { - HashSet that = new HashSet<>(); - c.forEach(that::add); - predicate = that::contains; - } - boolean removed = false; - for (Iterator i = iterator(); i.hasNext(); ) { - E e = i.next(); - if (!predicate.test(e)) { - i.remove(); - removed = true; - } - } - return removed; - } - - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof AbstractMutableChampSet) { - AbstractMutableChampSet that = (AbstractMutableChampSet) o; - return size == that.size && root.equivalent(that.root); - } - return super.equals(o); - } - - /** - * Returns the current value of the modification counter. - * - * @return value of modification counter - */ - protected int getModCount() { - return modCount; - } - - @Override - public int size() { - return size; - } - - /** - * Gets the owner id of this set. Creates a new id, if this - * set has no owner id. - * - * @return a new unique id or the existing unique id. - */ - @NonNull - protected IdentityObject makeOwner() { - if (owner == null) { - owner = new IdentityObject(); - } - return owner; - } - - @Override - public boolean removeAll(@NonNull Collection c) { - return removeAll((Iterable) c); - } - - /** - * Removes all specified elements that are in this set. - * - * @param c an iterable of elements - * @return {@code true} if this set changed - */ - public boolean removeAll(@NonNull Iterable c) { - if (isEmpty()) { - return false; - } - if (c == this) { - clear(); - return true; - } - boolean modified = false; - for (Object o : c) { - modified |= remove(o); - } - return modified; - } - - @Override - public Stream stream() { - return super.stream(); - } - - @Override - @SuppressWarnings("unchecked") - public @NonNull AbstractMutableChampSet clone() { - try { - owner = null; - return (AbstractMutableChampSet) super.clone(); - } catch (CloneNotSupportedException e) { - throw new InternalError(e); - } - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/BitmapIndexedNode.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/BitmapIndexedNode.java deleted file mode 100644 index 6ce92737f..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/BitmapIndexedNode.java +++ /dev/null @@ -1,716 +0,0 @@ -/* - * @(#)BitmapIndexedNode.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.impl.champ; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.impl.IdentityObject; -import org.jhotdraw8.collection.util.ListHelper; - -import java.util.Arrays; -import java.util.function.BiFunction; -import java.util.function.BiPredicate; -import java.util.function.Predicate; -import java.util.function.ToIntFunction; - -import static org.jhotdraw8.collection.impl.champ.NodeFactory.newBitmapIndexedNode; - - -/** - * Represents a bitmap-indexed node in a CHAMP trie. - *

- * References: - *

- * This class has been derived from 'The Capsule Hash Trie Collections Library'. - *

- *
The Capsule Hash Trie Collections Library. - *
Copyright (c) Michael Steindorfer. BSD-2-Clause License
- *
github.com - *
- * - * @param the data type - */ -public class BitmapIndexedNode extends Node { - static final @NonNull BitmapIndexedNode EMPTY_NODE = new BitmapIndexedNode<>(0, 0, new Object[]{}); - /** - * True if data elements are stored at the beginning of the array, and node elements at the end. - */ - final static boolean DATA_FIRST = true; - - - public final Object @NonNull [] mixed; - private final int nodeMap; - private final int dataMap; - - protected BitmapIndexedNode(int nodeMap, - int dataMap, @NonNull Object @NonNull [] mixed) { - this.nodeMap = nodeMap; - this.dataMap = dataMap; - this.mixed = mixed; - assert mixed.length == nodeArity() + dataArity(); - } - - @SuppressWarnings("unchecked") - public static @NonNull BitmapIndexedNode emptyNode() { - return (BitmapIndexedNode) EMPTY_NODE; - } - - private int dataMixedIndex(int dataIndex, Object[] mx) { - if (DATA_FIRST) { - return dataIndex; - } else { - return mx.length - 1 - dataIndex; - } - } - - private int nodeMixedIndex(int nodeIndex, Object[] mx) { - if (DATA_FIRST) { - return mx.length - 1 - nodeIndex; - } else { - return nodeIndex; - } - } - - @NonNull BitmapIndexedNode copyAndInsertData(@Nullable IdentityObject owner, int mask, - D data) { - int idx = dataMixedIndex(dataIndex(mask), mixed); - if (!DATA_FIRST) { - idx++; - } - Object[] dst = ListHelper.copyComponentAdd(this.mixed, idx, 1); - dst[idx] = data; - /* - if (isAllowedToUpdate(owner)) { - this.mixed=dst; - this.dataMap=dataMap | mask; - return this; - }*/ - return newBitmapIndexedNode(owner, nodeMap, dataMap | mask, dst); - } - - @NonNull BitmapIndexedNode copyAndMigrateFromDataToNode(@Nullable IdentityObject owner, - int mask, Node node) { - - int idxOld = dataMixedIndex(dataIndex(mask), mixed); - int idxNew = nodeMixedIndex(nodeIndex(mask), mixed); - - // copy 'src' and remove entryLength element(s) at position 'idxOld' and - // insert 1 element(s) at position 'idxNew' - Object[] src = this.mixed; - Object[] dst = new Object[src.length]; - if (DATA_FIRST) { - assert idxOld <= idxNew; - System.arraycopy(src, 0, dst, 0, idxOld); - System.arraycopy(src, idxOld + 1, dst, idxOld, idxNew - idxOld); - System.arraycopy(src, idxNew + 1, dst, idxNew + 1, src.length - idxNew - 1); - } else { - assert idxOld >= idxNew; - System.arraycopy(src, 0, dst, 0, idxNew); - System.arraycopy(src, idxNew, dst, idxNew + 1, idxOld - idxNew); - System.arraycopy(src, idxOld + 1, dst, idxOld + 1, src.length - idxOld - 1); - } - dst[idxNew] = node; - - return newBitmapIndexedNode(owner, nodeMap | mask, dataMap ^ mask, dst); - } - - @NonNull BitmapIndexedNode copyAndMigrateFromNodeToData(@Nullable IdentityObject owner, - int mask, @NonNull Node node) { - int idxOld = nodeMixedIndex(nodeIndex(mask), mixed); - int idxNew = dataMixedIndex(dataIndex(mask), mixed); - - // copy 'src' and remove 1 element(s) at position 'idxOld' and - // insert entryLength element(s) at position 'idxNew' - Object[] src = this.mixed; - Object[] dst = new Object[src.length]; - if (DATA_FIRST) { - assert idxOld >= idxNew; - System.arraycopy(src, 0, dst, 0, idxNew); - System.arraycopy(src, idxNew, dst, idxNew + 1, idxOld - idxNew); - System.arraycopy(src, idxOld + 1, dst, idxOld + 1, src.length - idxOld - 1); - } else { - assert idxOld <= idxNew; - System.arraycopy(src, 0, dst, 0, idxOld); - System.arraycopy(src, idxOld + 1, dst, idxOld, idxNew - idxOld); - System.arraycopy(src, idxNew + 1, dst, idxNew + 1, src.length - idxNew - 1); - } - dst[idxNew] = node.getData(0); - return newBitmapIndexedNode(owner, nodeMap ^ mask, dataMap | mask, dst); - } - - @NonNull BitmapIndexedNode copyAndSetNode(@Nullable IdentityObject owner, int mask, - Node node) { - - int idx = nodeMixedIndex(nodeIndex(mask), mixed); - if (isAllowedToUpdate(owner)) { - // no copying if already editable - this.mixed[idx] = node; - return this; - } else { - // copy 'src' and set 1 element(s) at position 'idx' - final Object[] dst = ListHelper.copySet(this.mixed, idx, node); - return newBitmapIndexedNode(owner, nodeMap, dataMap, dst); - } - } - - @Override - int dataArity() { - return Integer.bitCount(dataMap); - } - - int dataIndex(int mask) { - return Integer.bitCount(dataMap & (mask - 1)); - } - - int index(int map, int mask) { - return Integer.bitCount(map & (mask - 1)); - } - - public int dataMap() { - return dataMap; - } - - @SuppressWarnings("unchecked") - @Override - protected boolean equivalent(@NonNull Object other) { - if (this == other) { - return true; - } - BitmapIndexedNode that = (BitmapIndexedNode) other; - Object[] thatNodes = that.mixed; - // nodes array: we compare local data from 0 to splitAt (excluded) - // and then we compare the nested nodes from splitAt to length (excluded) - if (DATA_FIRST) { - int splitAt = dataArity(); - return nodeMap() == that.nodeMap() - && dataMap() == that.dataMap() - && Arrays.equals(mixed, 0, splitAt, thatNodes, 0, splitAt) - && Arrays.equals(mixed, splitAt, mixed.length, thatNodes, splitAt, thatNodes.length, - (a, b) -> ((Node) a).equivalent(b) ? 0 : 1); - } else { - int splitAt = nodeArity(); - return nodeMap() == that.nodeMap() - && dataMap() == that.dataMap() - && Arrays.equals(mixed, 0, splitAt, thatNodes, 0, splitAt, - (a, b) -> ((Node) a).equivalent(b) ? 0 : 1) - && Arrays.equals(mixed, splitAt, mixed.length, thatNodes, splitAt, thatNodes.length); - } - } - - - @Override - @Nullable - public Object find(D key, int dataHash, int shift, @NonNull BiPredicate equalsFunction) { - int mask = mask(bitpos(dataHash, shift)); - if ((nodeMap & mask) != 0) { - return getNode(nodeIndex(mask)).find(key, dataHash, shift + BIT_PARTITION_SIZE, equalsFunction); - } - if ((dataMap & mask) != 0) { - D k = getData(dataIndex(mask)); - if (equalsFunction.test(k, key)) { - return k; - } - } - return NO_DATA; - } - - - @Override - @SuppressWarnings("unchecked") - @NonNull - D getData(int index) { - return (D) mixed[dataMixedIndex(index, mixed)]; - } - - - @Override - @SuppressWarnings("unchecked") - @NonNull - Node getNode(int index) { - return (Node) mixed[nodeMixedIndex(index, mixed)]; - } - - @Override - - @NonNull - Object getNodeRaw(int index) { - return mixed[nodeMixedIndex(index, mixed)]; - } - - @Override - boolean hasData() { - return dataMap != 0; - } - - @Override - boolean hasDataArityOne() { - return Integer.bitCount(dataMap) == 1; - } - - @Override - boolean hasNodes() { - return nodeMap != 0; - } - - @Override - int nodeArity() { - return Integer.bitCount(nodeMap); - } - - int nodeIndex(int mask) { - return Integer.bitCount(nodeMap & (mask - 1)); - } - - public int nodeMap() { - return nodeMap; - } - - @Override - @NonNull - public BitmapIndexedNode remove(@Nullable IdentityObject owner, - D data, - int dataHash, int shift, - @NonNull ChangeEvent details, @NonNull BiPredicate equalsFunction) { - int bitpos = bitpos(dataHash, shift); - int mask = mask(bitpos); - if ((dataMap & mask) != 0) { - return removeData(owner, data, dataHash, shift, details, mask, equalsFunction); - } - if ((nodeMap & mask) != 0) { - return removeSubNode(owner, data, dataHash, shift, details, mask, equalsFunction); - } - return this; - } - - private @NonNull BitmapIndexedNode removeData(@Nullable IdentityObject owner, D data, int dataHash, int shift, @NonNull ChangeEvent details, int mask, @NonNull BiPredicate equalsFunction) { - int dataIndex = dataIndex(mask); - if (!equalsFunction.test(getData(dataIndex), data)) { - return this; - } - D currentVal = getData(dataIndex); - details.setRemoved(currentVal); - if (dataArity() == 2 && !hasNodes()) { - int newDataMap = - (shift == 0) ? (dataMap ^ mask) : mask(bitpos(dataHash, 0)); - Object[] nodes = {getData(dataIndex ^ 1)}; - return newBitmapIndexedNode(owner, 0, newDataMap, nodes); - } - int idx = dataMixedIndex(dataIndex, mixed); - Object[] dst = ListHelper.copyComponentRemove(this.mixed, idx, 1); - return newBitmapIndexedNode(owner, nodeMap, dataMap ^ mask, dst); - } - - private @NonNull BitmapIndexedNode removeSubNode(@Nullable IdentityObject owner, D data, int dataHash, int shift, - @NonNull ChangeEvent details, - int mask, @NonNull BiPredicate equalsFunction) { - Node subNode = getNode(nodeIndex(mask)); - Node updatedSubNode = - subNode.remove(owner, data, dataHash, shift + BIT_PARTITION_SIZE, details, equalsFunction); - if (subNode == updatedSubNode) { - return this; - } - if (!updatedSubNode.hasNodes() && updatedSubNode.hasDataArityOne()) { - if (!hasData() && nodeArity() == 1) { - return (BitmapIndexedNode) updatedSubNode; - } - return copyAndMigrateFromNodeToData(owner, mask, updatedSubNode); - } - return copyAndSetNode(owner, mask, updatedSubNode); - } - - @Override - @NonNull - public BitmapIndexedNode put(@Nullable IdentityObject owner, - @Nullable D newData, - int dataHash, int shift, - @NonNull ChangeEvent details, - @NonNull BiFunction updateFunction, - @NonNull BiPredicate equalsFunction, - @NonNull ToIntFunction hashFunction) { - int bitpos = bitpos(dataHash, shift); - int mask = mask(bitpos); - if ((dataMap & mask) != 0) { - final int dataIndex = dataIndex(mask); - final D oldData = getData(dataIndex); - if (equalsFunction.test(oldData, newData)) { - D updatedData = updateFunction.apply(oldData, newData); - if (updatedData == oldData) { - details.found(oldData); - return this; - } - details.setReplaced(oldData, updatedData); - return copyAndSetData(owner, dataIndex, updatedData); - } - Node updatedSubNode = - mergeTwoDataEntriesIntoNode(owner, - oldData, hashFunction.applyAsInt(oldData), - newData, dataHash, shift + BIT_PARTITION_SIZE); - details.setAdded(newData); - return copyAndMigrateFromDataToNode(owner, mask, updatedSubNode); - } - if ((nodeMap & mask) != 0) { - Node subNode = getNode(nodeIndex(mask)); - Node updatedSubNode = subNode - .put(owner, newData, dataHash, shift + BIT_PARTITION_SIZE, details, updateFunction, equalsFunction, hashFunction); - return subNode == updatedSubNode ? this : copyAndSetNode(owner, mask, updatedSubNode); - } - details.setAdded(newData); - return copyAndInsertData(owner, mask, newData); - } - - @NonNull - private BitmapIndexedNode copyAndSetData(@Nullable IdentityObject owner, int dataIndex, D updatedData) { - if (isAllowedToUpdate(owner)) { - this.mixed[dataMixedIndex(dataIndex, mixed)] = updatedData; - return this; - } - Object[] newMixed = ListHelper.copySet(this.mixed, dataMixedIndex(dataIndex, mixed), updatedData); - return newBitmapIndexedNode(owner, nodeMap, dataMap, newMixed); - } - - - @SuppressWarnings("unchecked") - @Override - @NonNull - public BitmapIndexedNode putAll(IdentityObject owner, Node other, int shift, - @NonNull BulkChangeEvent bulkChange, - @NonNull BiFunction updateFunction, - @NonNull BiPredicate equalsFunction, - @NonNull ToIntFunction hashFunction, - @NonNull ChangeEvent details) { - var that = (BitmapIndexedNode) other; - if (this == that) { - bulkChange.inBoth += this.calculateSize(); - return this; - } - - var newBitMap = nodeMap | dataMap | that.nodeMap | that.dataMap; - var buffer = new Object[Integer.bitCount(newBitMap)]; - int newDataMap = this.dataMap | that.dataMap; - int newNodeMap = this.nodeMap | that.nodeMap; - boolean changed = false; - for (int mapToDo = newBitMap; mapToDo != 0; mapToDo ^= Integer.lowestOneBit(mapToDo)) { - int bitpos = Integer.numberOfTrailingZeros(mapToDo); - int mask = mask(bitpos); - - boolean thisIsData = (this.dataMap & mask) != 0; - boolean thatIsData = (that.dataMap & mask) != 0; - boolean thisIsNode = (this.nodeMap & mask) != 0; - boolean thatIsNode = (that.nodeMap & mask) != 0; - - if (!(thisIsNode || thisIsData)) { - // add 'mixed' (data or node) from that trie - if (thatIsData) { - buffer[dataMixedIndex(index(newDataMap, mask), buffer)] = that.getData(that.dataIndex(mask)); - } else { - buffer[nodeMixedIndex(index(newNodeMap, mask), buffer)] = that.getNode(that.nodeIndex(mask)); - } - changed = true; - } else if (!(thatIsNode || thatIsData)) { - // add 'mixed' (data or node) from this trie - if (thisIsData) { - buffer[dataMixedIndex(index(newDataMap, mask), buffer)] = this.getData(dataIndex(mask)); - } else { - buffer[nodeMixedIndex(index(newNodeMap, mask), buffer)] = this.getNode(nodeIndex(mask)); - } - changed = true; - } else if (thisIsNode && thatIsNode) { - // add a new node that joins this node and that node - Node thisNode = this.getNode(this.nodeIndex(mask)); - Node thatNode = that.getNode(that.nodeIndex(mask)); - Node newNode = thisNode.putAll(owner, thatNode, shift + BIT_PARTITION_SIZE, bulkChange, - updateFunction, equalsFunction, hashFunction, details); - buffer[nodeMixedIndex(index(newNodeMap, mask), buffer)] = newNode; - changed |= thisNode != newNode; - } else if (thisIsData && thatIsNode) { - // add a new node that joins this data and that node - D thisData = this.getData(this.dataIndex(mask)); - Node thatNode = that.getNode(that.nodeIndex(mask)); - details.reset(); - buffer[nodeMixedIndex(index(newNodeMap, mask), buffer)] = thatNode.put(null, thisData, hashFunction.applyAsInt(thisData), shift + BIT_PARTITION_SIZE, details, - (a, b) -> updateFunction.apply(b, a), - equalsFunction, hashFunction); - if (details.isUnchanged()) { - bulkChange.inBoth++; - } else if (details.isReplaced()) { - bulkChange.replaced = true; - bulkChange.inBoth++; - } - newDataMap ^= mask; - changed = true; - } else if (thisIsNode) { - // add a new node that joins this node and that data - D thatData = that.getData(that.dataIndex(mask)); - Node thisNode = this.getNode(this.nodeIndex(mask)); - details.reset(); - buffer[nodeMixedIndex(index(newNodeMap, mask), buffer)] = thisNode.put(owner, thatData, hashFunction.applyAsInt(thatData), shift + BIT_PARTITION_SIZE, details, updateFunction, equalsFunction, hashFunction); - if (!details.isModified()) { - bulkChange.inBoth++; - } - newDataMap ^= mask; - changed = true; - } else { - // add a new node that joins this data and that data - D thisData = this.getData(this.dataIndex(mask)); - D thatData = that.getData(that.dataIndex(mask)); - if (equalsFunction.test(thisData, thatData)) { - bulkChange.inBoth++; - D updated = updateFunction.apply(thisData, thatData); - buffer[dataMixedIndex(index(newDataMap, mask), buffer)] = updated; - bulkChange.replaced |= updated != thisData; - } else { - newDataMap ^= mask; - newNodeMap ^= mask; - buffer[nodeMixedIndex(index(newNodeMap, mask), buffer)] = mergeTwoDataEntriesIntoNode(owner, thisData, hashFunction.applyAsInt(thisData), thatData, hashFunction.applyAsInt(thatData), shift + BIT_PARTITION_SIZE); - changed = true; - } - } - } - return changed ? new BitmapIndexedNode<>(newNodeMap, newDataMap, buffer) : this; - } - - @Override - @NonNull - public BitmapIndexedNode removeAll(@Nullable IdentityObject owner, Node other, int shift, @NonNull BulkChangeEvent bulkChange, @NonNull BiFunction updateFunction, @NonNull BiPredicate equalsFunction, @NonNull ToIntFunction hashFunction, @NonNull ChangeEvent details) { - var that = (BitmapIndexedNode) other; - if (this == that) { - bulkChange.inBoth += this.calculateSize(); - return this; - } - - var newBitMap = nodeMap | dataMap; - var buffer = new Object[Integer.bitCount(newBitMap)]; - int newDataMap = this.dataMap; - int newNodeMap = this.nodeMap; - for (int mapToDo = newBitMap; mapToDo != 0; mapToDo ^= Integer.lowestOneBit(mapToDo)) { - int bitpos = Integer.numberOfTrailingZeros(mapToDo); - int mask = mask(bitpos); - - boolean thisIsData = (this.dataMap & mask) != 0; - boolean thatIsData = (that.dataMap & mask) != 0; - boolean thisIsNode = (this.nodeMap & mask) != 0; - boolean thatIsNode = (that.nodeMap & mask) != 0; - - if (!(thisIsNode || thisIsData)) { - // programming error - assert false; - } else if (!(thatIsNode || thatIsData)) { - // keep 'mixed' (data or node) from this trie - if (thisIsData) { - buffer[dataMixedIndex(index(newDataMap, mask), buffer)] = this.getData(dataIndex(mask)); - } else { - buffer[nodeMixedIndex(index(newNodeMap, mask), buffer)] = this.getNode(nodeIndex(mask)); - } - } else if (thisIsNode && thatIsNode) { - // remove all in that node from all in this node - Node thisNode = this.getNode(this.nodeIndex(mask)); - Node thatNode = that.getNode(that.nodeIndex(mask)); - Node result = thisNode.removeAll(owner, thatNode, shift + BIT_PARTITION_SIZE, bulkChange, updateFunction, equalsFunction, hashFunction, details); - if (result.isNodeEmpty()) { - newNodeMap ^= mask; - } else if (result.hasMany()) { - buffer[nodeMixedIndex(index(newNodeMap, mask), buffer)] = result; - } else { - newNodeMap ^= mask; - newDataMap ^= mask; - buffer[dataMixedIndex(index(newDataMap, mask), buffer)] = result.getData(0); - } - } else if (thisIsData && thatIsNode) { - // remove this data if it is contained in that node - D thisData = this.getData(this.dataIndex(mask)); - Node thatNode = that.getNode(that.nodeIndex(mask)); - Object result = thatNode.find(thisData, hashFunction.applyAsInt(thisData), shift + BIT_PARTITION_SIZE, equalsFunction); - if (result == NO_DATA) { - buffer[dataMixedIndex(index(newDataMap, mask), buffer)] = thisData; - } else { - newDataMap ^= mask; - bulkChange.removed++; - } - } else if (thisIsNode) { - // remove that data from this node - D thatData = that.getData(that.dataIndex(mask)); - Node thisNode = this.getNode(this.nodeIndex(mask)); - details.reset(); - Node result = thisNode.remove(owner, thatData, hashFunction.applyAsInt(thatData), shift + BIT_PARTITION_SIZE, details, equalsFunction); - if (details.isModified()) { - bulkChange.removed++; - } - if (result.isNodeEmpty()) { - newNodeMap ^= mask; - } else if (result.hasMany()) { - buffer[nodeMixedIndex(index(newNodeMap, mask), buffer)] = result; - } else { - newDataMap ^= mask; - newNodeMap ^= mask; - buffer[dataMixedIndex(index(newDataMap, mask), buffer)] = result.getData(0); - } - } else { - // remove this data if it is equal to that data - D thisData = this.getData(this.dataIndex(mask)); - D thatData = that.getData(that.dataIndex(mask)); - if (equalsFunction.test(thisData, thatData)) { - bulkChange.removed++; - newDataMap ^= mask; - } else { - buffer[dataMixedIndex(index(newDataMap, mask), buffer)] = thisData; - } - } - } - return newCroppedBitmapIndexedNode(buffer, newDataMap, newNodeMap); - } - - @NonNull - private BitmapIndexedNode newCroppedBitmapIndexedNode(Object[] buffer, int newDataMap, int newNodeMap) { - int newLength = Integer.bitCount(newNodeMap | newDataMap); - if (newLength != buffer.length) { - Object[] temp = buffer; - buffer = new Object[newLength]; - int dataCount = Integer.bitCount(newDataMap); - int nodeCount = Integer.bitCount(newNodeMap); - if (DATA_FIRST) { - System.arraycopy(temp, 0, buffer, 0, dataCount); - System.arraycopy(temp, temp.length - nodeCount, buffer, dataCount, nodeCount); - } else { - System.arraycopy(temp, 0, buffer, 0, nodeCount); - System.arraycopy(temp, temp.length - dataCount, buffer, nodeCount, dataCount); - } - } - return new BitmapIndexedNode<>(newNodeMap, newDataMap, buffer); - } - - @Override - @NonNull - public BitmapIndexedNode retainAll(IdentityObject owner, Node other, int shift, @NonNull BulkChangeEvent bulkChange, @NonNull BiFunction updateFunction, @NonNull BiPredicate equalsFunction, @NonNull ToIntFunction hashFunction, @NonNull ChangeEvent details) { - var that = (BitmapIndexedNode) other; - if (this == that) { - bulkChange.inBoth += this.calculateSize(); - return this; - } - - var newBitMap = nodeMap | dataMap; - var buffer = new Object[Integer.bitCount(newBitMap)]; - int newDataMap = this.dataMap; - int newNodeMap = this.nodeMap; - for (int mapToDo = newBitMap; mapToDo != 0; mapToDo ^= Integer.lowestOneBit(mapToDo)) { - int bitpos = Integer.numberOfTrailingZeros(mapToDo); - int mask = mask(bitpos); - - boolean thisIsData = (this.dataMap & mask) != 0; - boolean thatIsData = (that.dataMap & mask) != 0; - boolean thisIsNode = (this.nodeMap & mask) != 0; - boolean thatIsNode = (that.nodeMap & mask) != 0; - - if (!(thisIsNode || thisIsData)) { - // programming error - assert false; - } else if (!(thatIsNode || thatIsData)) { - // remove 'mixed' (data or node) from this trie - if (thisIsData) { - newDataMap ^= mask; - bulkChange.removed++; - } else { - newNodeMap ^= mask; - bulkChange.removed += this.getNode(this.nodeIndex(mask)).calculateSize(); - } - } else if (thisIsNode && thatIsNode) { - // retain all in that node from all in this node - Node thisNode = this.getNode(this.nodeIndex(mask)); - Node thatNode = that.getNode(that.nodeIndex(mask)); - Node result = thisNode.retainAll(owner, thatNode, shift + BIT_PARTITION_SIZE, bulkChange, updateFunction, equalsFunction, hashFunction, details); - if (result.isNodeEmpty()) { - newNodeMap ^= mask; - } else if (result.hasMany()) { - buffer[nodeMixedIndex(index(newNodeMap, mask), buffer)] = result; - } else { - newNodeMap ^= mask; - newDataMap ^= mask; - buffer[dataMixedIndex(index(newDataMap, mask), buffer)] = result.getData(0); - } - } else if (thisIsData && thatIsNode) { - // retain this data if it is contained in that node - D thisData = this.getData(this.dataIndex(mask)); - Node thatNode = that.getNode(that.nodeIndex(mask)); - Object result = thatNode.find(thisData, hashFunction.applyAsInt(thisData), shift + BIT_PARTITION_SIZE, equalsFunction); - if (result == NO_DATA) { - newDataMap ^= mask; - bulkChange.removed++; - } else { - buffer[dataMixedIndex(index(newDataMap, mask), buffer)] = thisData; - } - } else if (thisIsNode) { - // retain this data if that data is contained in this node - D thatData = that.getData(that.dataIndex(mask)); - Node thisNode = this.getNode(this.nodeIndex(mask)); - Object result = thisNode.find(thatData, hashFunction.applyAsInt(thatData), shift + BIT_PARTITION_SIZE, equalsFunction); - if (result == NO_DATA) { - bulkChange.removed += this.getNode(this.nodeIndex(mask)).calculateSize(); - newNodeMap ^= mask; - } else { - newDataMap ^= mask; - newNodeMap ^= mask; - buffer[dataMixedIndex(index(newDataMap, mask), buffer)] = result; - bulkChange.removed += this.getNode(this.nodeIndex(mask)).calculateSize() - 1; - } - } else { - // retain this data if it is equal to that data - D thisData = this.getData(this.dataIndex(mask)); - D thatData = that.getData(that.dataIndex(mask)); - if (equalsFunction.test(thisData, thatData)) { - buffer[dataMixedIndex(index(newDataMap, mask), buffer)] = thisData; - } else { - bulkChange.removed++; - newDataMap ^= mask; - } - } - } - return newCroppedBitmapIndexedNode(buffer, newDataMap, newNodeMap); - } - - @Override - @NonNull - public BitmapIndexedNode filterAll(@Nullable IdentityObject owner, Predicate predicate, int shift, @NonNull BulkChangeEvent bulkChange) { - var newBitMap = nodeMap | dataMap; - var buffer = new Object[Integer.bitCount(newBitMap)]; - int newDataMap = this.dataMap; - int newNodeMap = this.nodeMap; - for (int mapToDo = newBitMap; mapToDo != 0; mapToDo ^= Integer.lowestOneBit(mapToDo)) { - int bitpos = Integer.numberOfTrailingZeros(mapToDo); - int mask = mask(bitpos); - boolean thisIsNode = (this.nodeMap & mask) != 0; - if (thisIsNode) { - Node thisNode = this.getNode(this.nodeIndex(mask)); - Node result = thisNode.filterAll(owner, predicate, shift + BIT_PARTITION_SIZE, bulkChange); - if (result.isNodeEmpty()) { - newNodeMap ^= mask; - } else if (result.hasMany()) { - buffer[nodeMixedIndex(index(newNodeMap, mask), buffer)] = result; - } else { - newNodeMap ^= mask; - newDataMap ^= mask; - buffer[dataMixedIndex(index(newDataMap, mask), buffer)] = result.getData(0); - } - } else { - D thisData = this.getData(this.dataIndex(mask)); - if (predicate.test(thisData)) { - buffer[dataMixedIndex(index(newDataMap, mask), buffer)] = thisData; - } else { - newDataMap ^= mask; - bulkChange.removed++; - } - } - } - return newCroppedBitmapIndexedNode(buffer, newDataMap, newNodeMap); - } - - protected int calculateSize() { - int size = dataArity(); - for (int i = 0, n = nodeArity(); i < n; i++) { - Node node = getNode(i); - size += node.calculateSize(); - } - return size; - } -} \ No newline at end of file diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/BulkChangeEvent.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/BulkChangeEvent.java deleted file mode 100644 index 24d703038..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/BulkChangeEvent.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.jhotdraw8.collection.impl.champ; - -public class BulkChangeEvent { - public int inBoth; - public boolean replaced; - public int removed; - - public void reset() { - inBoth = 0; - replaced = false; - removed = 0; - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/ChampIterator.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/ChampIterator.java deleted file mode 100644 index 1a81cce61..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/ChampIterator.java +++ /dev/null @@ -1,106 +0,0 @@ -package org.jhotdraw8.collection.impl.champ; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; - -import java.util.Iterator; -import java.util.NoSuchElementException; -import java.util.function.Function; - -/** - * CHAMP Trie iterator. - *

- * References: - *

- * This class has been derived from 'The Capsule Hash Trie Collections Library'. - *

- *
The Capsule Hash Trie Collections Library. - *
Copyright (c) Michael Steindorfer. BSD-2-Clause License
- *
github.com - *
* - * - * @param the data type of the trie node - * @param the element type of the iterator - */ -public class ChampIterator implements Iterator { - private final @NonNull Function mappingFunction; - private static final int MAX_DEPTH = 7; - - protected int currentValueCursor; - protected int currentValueLength; - protected Node currentValueNode; - - private int currentStackLevel = -1; - private final int[] indexAndArity = new int[MAX_DEPTH * 2]; - - @SuppressWarnings("unchecked") - Node[] nodes = new Node[MAX_DEPTH]; - - public ChampIterator(@NonNull Node rootNode, @Nullable Function mappingFunction) { - this.mappingFunction = mappingFunction == null ? k -> (E) k : mappingFunction; - if (rootNode.hasNodes()) { - currentStackLevel = 0; - - nodes[0] = rootNode; - indexAndArity[0] = 0; - indexAndArity[1] = rootNode.nodeArity(); - } - - if (rootNode.hasData()) { - currentValueNode = rootNode; - currentValueCursor = 0; - currentValueLength = rootNode.dataArity(); - } - } - - /* - * search for next node that contains values - */ - private boolean searchNextValueNode() { - // For inlining, it is essential that this method has a very small amount of byte code! - while (currentStackLevel >= 0) { - var index = currentStackLevel << 1; - if (indexAndArity[index] < indexAndArity[index + 1]) { - var nextNode = nodes[currentStackLevel].getNode(indexAndArity[index]); - indexAndArity[index]++; - if (nextNode.hasNodes()) { - // put node on next stack level for depth-first traversal - ++currentStackLevel; - index += 2; - nodes[currentStackLevel] = nextNode; - indexAndArity[index] = 0; - indexAndArity[index + 1] = nextNode.nodeArity(); - } - if (nextNode.hasData()) { - // found next node that contains values - currentValueNode = nextNode; - currentValueCursor = 0; - currentValueLength = nextNode.dataArity(); - return true; - } - } else { - currentStackLevel--; - } - } - return false; - } - - public boolean hasNext() { - // For inlining, it is essential that this method has a very small amount of byte code! - // Specifically, do not inline searchNextValueNode() into this method! - return currentValueCursor < currentValueLength || searchNextValueNode(); - } - - @Override - public E next() { - if (!hasNext()) { - throw new NoSuchElementException(); - } else { - return mappingFunction.apply(currentValueNode.getData(currentValueCursor++)); - } - } - - public void remove() { - throw new UnsupportedOperationException(); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/ChampSpliterator.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/ChampSpliterator.java deleted file mode 100644 index c98101727..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/ChampSpliterator.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * @(#)KeySpliterator.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.impl.champ; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; - -import java.util.Spliterators; -import java.util.function.Consumer; -import java.util.function.Function; - -/** - * Data iterator over a CHAMP trie. - *

- * References: - *

- * This class has been derived from 'The Capsule Hash Trie Collections Library'. - *

- *
The Capsule Hash Trie Collections Library. - *
Copyright (c) Michael Steindorfer. BSD-2-Clause License
- *
github.com - *
* - * - * @param the data type of the trie node - * @param the element type of the iterator - */ -public class ChampSpliterator extends Spliterators.AbstractSpliterator { - private final @NonNull Function mappingFunction; - private static final int MAX_DEPTH = 7; - - protected int currentValueCursor; - protected int currentValueLength; - protected Node currentValueNode; - - private int currentStackLevel = -1; - - /** - * Even indexes: node index - * Odd indexes: node length - */ - private final int[] indexAndArity = new int[MAX_DEPTH * 2]; - - @SuppressWarnings("unchecked") - Node[] nodes = new Node[MAX_DEPTH]; - private K current; - - @SuppressWarnings("unchecked") - public ChampSpliterator(@NonNull Node rootNode, @Nullable Function mappingFunction, long size, int characteristics) { - super(size, characteristics); - this.mappingFunction = mappingFunction == null ? k -> (E) k : mappingFunction; - if (rootNode.hasNodes()) { - currentStackLevel = 0; - - nodes[0] = rootNode; - indexAndArity[0] = 0; - indexAndArity[1] = rootNode.nodeArity(); - } - - if (rootNode.hasData()) { - currentValueNode = rootNode; - currentValueCursor = 0; - currentValueLength = rootNode.dataArity(); - } - } - - private boolean searchNextValueNode() { - // For inlining, it is essential that this method has a very small amount of byte code! - while (currentStackLevel >= 0) { - var index = currentStackLevel << 1; - if (indexAndArity[index] < indexAndArity[index + 1]) { - var nextNode = nodes[currentStackLevel].getNode(indexAndArity[index]); - indexAndArity[index]++; - if (nextNode.hasNodes()) { - ++currentStackLevel; - index += 2; - nodes[currentStackLevel] = nextNode; - indexAndArity[index] = 0; - indexAndArity[index + 1] = nextNode.nodeArity(); - } - if (nextNode.hasData()) { - currentValueNode = nextNode; - currentValueCursor = 0; - currentValueLength = nextNode.dataArity(); - return true; - } - } else { - currentStackLevel--; - } - } - return false; - } - - @Override - public boolean tryAdvance(@NonNull Consumer action) { - // For inlining, it is essential that this method has a very small amount of byte code! - // Specifically, do not inline searchNextValueNode() into this method! - if (currentValueCursor < currentValueLength || searchNextValueNode()) { - action.accept(mappingFunction.apply(currentValueNode.getData(currentValueCursor++))); - return true; - } - return false; - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/ChangeEvent.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/ChangeEvent.java deleted file mode 100644 index d18359ab0..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/ChangeEvent.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * @(#)ChangeEvent.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.impl.champ; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; - -import java.util.Objects; - -/** - * This class is used to report a change (or no changes) of data in a CHAMP trie. - * - * @param the data type - */ -public class ChangeEvent { - public boolean isUnchanged() { - return type == Type.UNCHANGED; - } - - enum Type { - UNCHANGED, - ADDED, - REMOVED, - REPLACED - } - - private @NonNull Type type = Type.UNCHANGED; - private @Nullable D oldData; - private @Nullable D newData; - - - - void found(D data) { - this.oldData = data; - } - - public @Nullable D getOldData() { - return oldData; - } - - public @Nullable D getNewData() { - return newData; - } - - public @NonNull D getOldDataNonNull() { - return Objects.requireNonNull(oldData); - } - - public @NonNull D getNewDataNonNull() { - return Objects.requireNonNull(newData); - } - - /** - * Call this method to indicate that the value of an element has changed. - * - * @param oldData the old value of the element - * @param newData the new value of the element - */ - void setReplaced(@Nullable D oldData, @Nullable D newData) { - this.oldData = oldData; - this.newData = newData; - this.type = Type.REPLACED; - } - - /** - * Call this method to indicate that an element has been removed. - * - * @param oldData the value of the removed element - */ - void setRemoved(@Nullable D oldData) { - this.oldData = oldData; - this.type = Type.REMOVED; - } - - /** - * Call this method to indicate that a data element has been added. - */ - void setAdded(@Nullable D newData) { - this.newData = newData; - this.type = Type.ADDED; - } - - /** - * Returns true if the CHAMP trie has been modified. - */ - public boolean isModified() { - return type != Type.UNCHANGED; - } - - /** - * Returns true if the data element has been replaced. - */ - public boolean isReplaced() { - return type == Type.REPLACED; - } - - public void resetModified() { - type = Type.UNCHANGED; - } - - public void reset() { - type = Type.UNCHANGED; - oldData = null; - newData = null; - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/HashCollisionNode.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/HashCollisionNode.java deleted file mode 100644 index 2388d2a6b..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/HashCollisionNode.java +++ /dev/null @@ -1,357 +0,0 @@ -/* - * @(#)HashCollisionNode.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.impl.champ; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.impl.IdentityObject; -import org.jhotdraw8.collection.util.ListHelper; - -import java.util.Arrays; -import java.util.Objects; -import java.util.function.BiFunction; -import java.util.function.BiPredicate; -import java.util.function.Predicate; -import java.util.function.ToIntFunction; - -import static org.jhotdraw8.collection.impl.champ.NodeFactory.newHashCollisionNode; - -/** - * Represents a hash-collision node in a CHAMP trie. - *

- * XXX hash-collision nodes may become huge performance bottlenecks. - * If the trie contains keys that implement {@link Comparable} then a hash-collision - * nodes should be a sorted tree structure (for example a red-black tree). - * Otherwise, hash-collision node should be a vector (for example a bit mapped trie). - *

- * References: - *

- * This class has been derived from 'The Capsule Hash Trie Collections Library'. - *

- *
The Capsule Hash Trie Collections Library. - *
Copyright (c) Michael Steindorfer. BSD-2-Clause License
- *
github.com - *
- * - * @param the data type - */ -class HashCollisionNode extends Node { - private static final HashCollisionNode EMPTY = new HashCollisionNode<>(new Object[0]); - - @NonNull Object[] data; - - HashCollisionNode(Object @NonNull [] data) { - this.data = data; - } - - @Override - int dataArity() { - return data.length; - } - - @Override - boolean hasDataArityOne() { - return false; - } - - @SuppressWarnings("unchecked") - @Override - boolean equivalent(@NonNull Object other) { - if (this == other) { - return true; - } - HashCollisionNode that = (HashCollisionNode) other; - @NonNull Object[] thatEntries = that.data; - if (thatEntries.length != data.length) { - return false; - } - - // Linear scan for each key, because of arbitrary element order. - @NonNull Object[] thatEntriesCloned = thatEntries.clone(); - int remainingLength = thatEntriesCloned.length; - outerLoop: - for (Object key : data) { - for (int j = 0; j < remainingLength; j += 1) { - Object todoKey = thatEntriesCloned[j]; - if (Objects.equals(todoKey, key)) { - // We have found an equal entry. We do not need to compare - // this entry again. So we replace it with the last entry - // from the array and reduce the remaining length. - System.arraycopy(thatEntriesCloned, remainingLength - 1, thatEntriesCloned, j, 1); - remainingLength -= 1; - - continue outerLoop; - } - } - return false; - } - - return true; - } - - @SuppressWarnings("unchecked") - @Override - @Nullable - Object find(D key, int dataHash, int shift, @NonNull BiPredicate equalsFunction) { - for (Object entry : data) { - if (equalsFunction.test(key, (D) entry)) { - return entry; - } - } - return NO_DATA; - } - - @Override - @SuppressWarnings("unchecked") - @NonNull - D getData(int index) { - return (D) data[index]; - } - - @Override - @NonNull - Node getNode(int index) { - throw new IllegalStateException("Is leaf node."); - } - - @Override - @NonNull - Object getNodeRaw(int index) { - throw new IllegalStateException("Is leaf node."); - } - - - @Override - boolean hasData() { - return data.length > 0; - } - - @Override - boolean hasNodes() { - return false; - } - - @Override - int nodeArity() { - return 0; - } - - - @SuppressWarnings("unchecked") - @Override - @NonNull - Node remove(@Nullable IdentityObject owner, D data, - int dataHash, int shift, @NonNull ChangeEvent details, @NonNull BiPredicate equalsFunction) { - for (int idx = 0, i = 0; i < this.data.length; i += 1, idx++) { - if (equalsFunction.test((D) this.data[i], data)) { - @SuppressWarnings("unchecked") D currentVal = (D) this.data[i]; - details.setRemoved(currentVal); - - if (this.data.length == 1) { - return BitmapIndexedNode.emptyNode(); - } else if (this.data.length == 2) { - // Create root node with singleton element. - // This node will either be the new root - // returned, or be unwrapped and inlined. - return NodeFactory.newBitmapIndexedNode(owner, 0, mask(bitpos(dataHash, 0)), - new Object[]{getData(idx ^ 1)}); - } - // copy keys and remove 1 element at position idx - Object[] entriesNew = ListHelper.copyComponentRemove(this.data, idx, 1); - if (isAllowedToUpdate(owner)) { - this.data = entriesNew; - return this; - } - return newHashCollisionNode(owner, dataHash, entriesNew); - } - } - return this; - } - - @SuppressWarnings("unchecked") - @Override - @NonNull - Node put(@Nullable IdentityObject owner, D newData, - int dataHash, int shift, @NonNull ChangeEvent details, - @NonNull BiFunction updateFunction, @NonNull BiPredicate equalsFunction, - @NonNull ToIntFunction hashFunction) { - - for (int i = 0; i < this.data.length; i++) { - D oldData = (D) this.data[i]; - if (equalsFunction.test(oldData, newData)) { - D updatedData = updateFunction.apply(oldData, newData); - if (updatedData == oldData) { - details.found(oldData); - return this; - } - details.setReplaced(oldData, updatedData); - if (isAllowedToUpdate(owner)) { - this.data[i] = updatedData; - return this; - } - final Object[] newKeys = ListHelper.copySet(this.data, i, updatedData); - return newHashCollisionNode(owner, dataHash, newKeys); - } - } - - // copy entries and add 1 more at the end - Object[] entriesNew = ListHelper.copyComponentAdd(this.data, this.data.length, 1); - entriesNew[this.data.length] = newData; - details.setAdded(newData); - if (isAllowedToUpdate(owner)) { - this.data = entriesNew; - return this; - } - return newHashCollisionNode(owner, dataHash, entriesNew); - } - - @Override - protected int calculateSize() { - return dataArity(); - } - - @SuppressWarnings("unchecked") - @Override - protected @NonNull Node putAll(@Nullable IdentityObject owner, Node otherNode, int shift, @NonNull BulkChangeEvent bulkChange, @NonNull BiFunction updateFunction, @NonNull BiPredicate equalsFunction, @NonNull ToIntFunction hashFunction, @NonNull ChangeEvent details) { - if (otherNode == this) { - bulkChange.inBoth += dataArity(); - return this; - } - HashCollisionNode that = (HashCollisionNode) otherNode; - - // The buffer initially contains all data elements from this node. - // Every time we find a matching data element in both nodes, we do not need to ever look at that data element again. - // So, we swap it out with a data element from the end of unprocessed data elements, and subtract 1 from unprocessedSize. - // If that node contains a data element that is not in this node, we add it to the end, and add 1 to bufferSize. - // Buffer content: - // 0..unprocessedSize-1 = unprocessed data elements from this node - // unprocessedSize..resultSize-1 = data elements that we have updated from that node, or that we have added from that node. - final int thisSize = this.dataArity(); - final int thatSize = that.dataArity(); - Object[] buffer = Arrays.copyOf(this.data, thisSize + thatSize); - System.arraycopy(this.data, 0, buffer, 0, this.data.length); - Object[] thatArray = that.data; - int resultSize = thisSize; - int unprocessedSize = thisSize; - boolean updated = false; - outer: - for (int i = 0; i < thatSize; i++) { - D thatData = (D) thatArray[i]; - for (int j = 0; j < unprocessedSize; j++) { - D thisData = (D) buffer[j]; - if (equalsFunction.test(thatData, thisData)) { - D swap = (D) buffer[--unprocessedSize]; - D updatedData = updateFunction.apply(thisData, thatData); - updated |= updatedData != thisData; - buffer[unprocessedSize] = updatedData; - buffer[j] = swap; - bulkChange.inBoth++; - continue outer; - } - } - buffer[resultSize++] = thatData; - } - return newCroppedHashCollisionNode(updated | resultSize != thisSize, buffer, resultSize); - } - - @SuppressWarnings("unchecked") - @Override - protected @NonNull Node removeAll(@Nullable IdentityObject owner, @NonNull Node otherNode, int shift, @NonNull BulkChangeEvent bulkChange, @NonNull BiFunction updateFunction, @NonNull BiPredicate equalsFunction, @NonNull ToIntFunction hashFunction, @NonNull ChangeEvent details) { - if (otherNode == this) { - bulkChange.removed += dataArity(); - return (Node) EMPTY; - } - HashCollisionNode that = (HashCollisionNode) otherNode; - - // The buffer initially contains all data elements from this node. - // Every time we find a data element that must be removed, we replace it with the last element from the - // result part of the buffer, and reduce resultSize by 1. - // Buffer content: - // 0..resultSize-1 = data elements from this node that have not been removed - final int thisSize = this.dataArity(); - final int thatSize = that.dataArity(); - int resultSize = thisSize; - Object[] buffer = this.data.clone(); - Object[] thatArray = that.data; - outer: - for (int i = 0; i < thatSize && resultSize > 0; i++) { - D thatData = (D) thatArray[i]; - for (int j = 0; j < resultSize; j++) { - D thisData = (D) buffer[j]; - if (equalsFunction.test(thatData, thisData)) { - buffer[j] = buffer[--resultSize]; - bulkChange.removed++; - continue outer; - } - } - } - return newCroppedHashCollisionNode(thisSize != resultSize, buffer, resultSize); - } - - @NonNull - private HashCollisionNode newCroppedHashCollisionNode(boolean changed, Object[] buffer, int size) { - if (changed) { - if (buffer.length != size) { - buffer = Arrays.copyOf(buffer, size); - } - return new HashCollisionNode<>(buffer); - } - return this; - } - - @SuppressWarnings("unchecked") - @Override - protected @NonNull Node retainAll(IdentityObject owner, Node otherNode, int shift, @NonNull BulkChangeEvent bulkChange, @NonNull BiFunction updateFunction, @NonNull BiPredicate equalsFunction, @NonNull ToIntFunction hashFunction, @NonNull ChangeEvent details) { - if (otherNode == this) { - bulkChange.removed += dataArity(); - return (Node) EMPTY; - } - HashCollisionNode that = (HashCollisionNode) otherNode; - - // The buffer initially contains all data elements from this node. - // Every time we find a data element that must be retained, we swap it into the result-part of the buffer. - // 0..resultSize-1 = data elements from this node that must be retained - // resultSize..thisSize-1 = data elements that might need to be retained - final int thisSize = this.dataArity(); - final int thatSize = that.dataArity(); - int resultSize = 0; - Object[] buffer = this.data.clone(); - Object[] thatArray = that.data; - outer: - for (int i = 0; i < thatSize && thisSize != resultSize; i++) { - D thatData = (D) thatArray[i]; - for (int j = resultSize; j < thisSize; j++) { - D thisData = (D) buffer[j]; - if (equalsFunction.test(thatData, thisData)) { - D swap = (D) buffer[resultSize]; - buffer[resultSize++] = thisData; - buffer[j] = swap; - continue outer; - } - } - bulkChange.removed++; - } - return newCroppedHashCollisionNode(thisSize != resultSize, buffer, resultSize); - } - - @SuppressWarnings("unchecked") - @Override - protected @NonNull Node filterAll(@Nullable IdentityObject owner, Predicate predicate, int shift, @NonNull BulkChangeEvent bulkChange) { - final int thisSize = this.dataArity(); - int resultSize = 0; - Object[] buffer = new Object[thisSize]; - Object[] thisArray = this.data; - for (int i = 0; i < thisSize; i++) { - D thisData = (D) thisArray[i]; - if (predicate.test(thisData)) { - buffer[resultSize++] = thisData; - } else { - bulkChange.removed++; - } - } - return newCroppedHashCollisionNode(thisSize != resultSize, buffer, resultSize); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/MutableBitmapIndexedNode.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/MutableBitmapIndexedNode.java deleted file mode 100644 index 8240993cd..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/MutableBitmapIndexedNode.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * @(#)MutableBitmapIndexedNode.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.impl.champ; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.impl.IdentityObject; - -/** - * A {@link BitmapIndexedNode} that provides storage space for a 'owner' identity. - *

- * References: - *

- * This class has been derived from 'The Capsule Hash Trie Collections Library'. - *

- *
The Capsule Hash Trie Collections Library. - *
Copyright (c) Michael Steindorfer. BSD-2-Clause License
- *
github.com - *
- * - * @param - */ -class MutableBitmapIndexedNode extends BitmapIndexedNode { - private static final long serialVersionUID = 0L; - private final @NonNull IdentityObject ownedBy; - - MutableBitmapIndexedNode(@NonNull IdentityObject ownedBy, int nodeMap, int dataMap, @NonNull Object @NonNull [] nodes) { - super(nodeMap, dataMap, nodes); - this.ownedBy = ownedBy; - } - - @Override - protected @NonNull IdentityObject getOwner() { - return ownedBy; - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/MutableHashCollisionNode.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/MutableHashCollisionNode.java deleted file mode 100644 index 8121dec14..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/MutableHashCollisionNode.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * @(#)MutableHashCollisionNode.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.impl.champ; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.impl.IdentityObject; - -/** - * A {@link HashCollisionNode} that provides storage space for a 'owner' identity. - *

- * References: - *

- * This class has been derived from 'The Capsule Hash Trie Collections Library'. - *

- *
The Capsule Hash Trie Collections Library. - *
Copyright (c) Michael Steindorfer. BSD-2-Clause License
- *
github.com - *
- * - * @param - */ -class MutableHashCollisionNode extends HashCollisionNode { - private static final long serialVersionUID = 0L; - private final @NonNull IdentityObject ownedBy; - - MutableHashCollisionNode(@NonNull IdentityObject ownedBy, Object @NonNull [] entries) { - super(entries); - this.ownedBy = ownedBy; - } - - @Override - protected @NonNull IdentityObject getOwner() { - return ownedBy; - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/Node.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/Node.java deleted file mode 100644 index 17e3587d2..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/Node.java +++ /dev/null @@ -1,366 +0,0 @@ -/* - * @(#)Node.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.impl.champ; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.impl.IdentityObject; - -import java.util.NoSuchElementException; -import java.util.function.BiFunction; -import java.util.function.BiPredicate; -import java.util.function.Predicate; -import java.util.function.ToIntFunction; - -/** - * Represents a node in a 'Compressed Hash-Array Mapped Prefix-tree' - * (CHAMP) trie. - *

- * A trie is a tree structure that stores a set of data objects; the - * path to a data object is determined by a bit sequence derived from the data - * object. - *

- * In a CHAMP trie, the bit sequence is derived from the hash code of a data - * object. A hash code is a bit sequence with a fixed length. This bit sequence - * is split up into parts. Each part is used as the index to the next child node - * in the tree, starting from the root node of the tree. - *

- * The nodes of a CHAMP trie are compressed. Instead of allocating a node for - * each data object, the data objects are stored directly in the ancestor node - * at which the path to the data object starts to become unique. This means, - * that in most cases, only a prefix of the bit sequence is needed for the - * path to a data object in the tree. - *

- * If the hash code of a data object in the set is not unique, then it is - * stored in a {@link HashCollisionNode}, otherwise it is stored in a - * {@link BitmapIndexedNode}. Since the hash codes have a fixed length, - * all {@link HashCollisionNode}s are located at the same, maximal depth - * of the tree. - *

- * In this implementation, a hash code has a length of - * {@value #HASH_CODE_LENGTH} bits, and is split up in little-endian order into parts of - * {@value #BIT_PARTITION_SIZE} bits (the last part contains the remaining bits). - *

- * References: - *

- * This class has been derived from 'The Capsule Hash Trie Collections Library'. - *

- *
The Capsule Hash Trie Collections Library. - *
Copyright (c) Michael Steindorfer. BSD-2-Clause License
- *
github.com - *
- * - * @param the type of the data objects that are stored in this trie - */ -public abstract class Node { - /** - * Represents no data. - * We can not use {@code null}, because we allow storing null-data in the - * trie. - */ - public static final Object NO_DATA = new Object(); - static final int HASH_CODE_LENGTH = 32; - /** - * Bit partition size in the range [1,5]. - *

- * The bit-mask must fit into the 32 bits of an int field ({@code 32 = 1<<5}). - * (You can use a size of 6, if you replace the bit-mask fields with longs). - */ - static final int BIT_PARTITION_SIZE = 5; - static final int BIT_PARTITION_MASK = (1 << BIT_PARTITION_SIZE) - 1; - static final int MAX_DEPTH = (HASH_CODE_LENGTH + BIT_PARTITION_SIZE - 1) / BIT_PARTITION_SIZE + 1; - static final int MAX_SHIFT = HASH_CODE_LENGTH - HASH_CODE_LENGTH % BIT_PARTITION_SIZE; - - - Node() { - } - - /** - * Given a masked bit-position, returns its mask - * in the bit-map. - *

- * For example, if the bit partition is 5 bits, then - * we 2^5 == 32 distinct bit-positions. - * If the masked dataHash is 3 then the bit-position is - * the bit with index 3. That is, 1<<3 = 0b0100. - * - * @param bitpos bitposition - * @return mask - */ - static int mask(int bitpos) { - return 1 << bitpos; - } - - public static @NonNull E getFirst(@NonNull Node node) { - while (node instanceof BitmapIndexedNode bxn) { - int nodeMap = bxn.nodeMap(); - int dataMap = bxn.dataMap(); - if ((nodeMap | dataMap) == 0) { - break; - } - int firstNodeBit = Integer.numberOfTrailingZeros(nodeMap); - int firstDataBit = Integer.numberOfTrailingZeros(dataMap); - if (nodeMap != 0 && firstNodeBit < firstDataBit) { - node = node.getNode(0); - } else { - return node.getData(0); - } - } - if (node instanceof HashCollisionNode hcn) { - return hcn.getData(0); - } - throw new NoSuchElementException(); - } - - public static @NonNull E getLast(@NonNull Node node) { - while (node instanceof BitmapIndexedNode bxn) { - int nodeMap = bxn.nodeMap(); - int dataMap = bxn.dataMap(); - if ((nodeMap | dataMap) == 0) { - break; - } - if (Integer.compareUnsigned(nodeMap, dataMap) > 0) { - node = node.getNode(node.nodeArity() - 1); - } else { - return node.getData(node.dataArity() - 1); - } - } - if (node instanceof HashCollisionNode hcn) { - return hcn.getData(hcn.dataArity() - 1); - } - throw new NoSuchElementException(); - } - - static int bitpos(int dataHash, int shift) { - return (dataHash >>> shift) & BIT_PARTITION_MASK; - } - - static @NonNull Node mergeTwoDataEntriesIntoNode(IdentityObject owner, - K k0, int keyHash0, - K k1, int keyHash1, - int shift) { - if (shift >= HASH_CODE_LENGTH) { - Object[] entries = new Object[2]; - entries[0] = k0; - entries[1] = k1; - return NodeFactory.newHashCollisionNode(owner, keyHash0, entries); - } - - int bitpos0 = bitpos(keyHash0, shift); - int bitpos1 = bitpos(keyHash1, shift); - - if (bitpos0 != bitpos1) { - // both nodes fit on same level - int dataMap = mask(bitpos0) | mask(bitpos1); - - Object[] entries = new Object[2]; - if (BitmapIndexedNode.DATA_FIRST) { - if (bitpos0 < bitpos1) { - entries[0] = k0; - entries[1] = k1; - } else { - entries[0] = k1; - entries[1] = k0; - } - } else { - if (bitpos0 < bitpos1) { - entries[0] = k1; - entries[1] = k0; - } else { - entries[0] = k0; - entries[1] = k1; - } - } - return NodeFactory.newBitmapIndexedNode(owner, (0), dataMap, entries); - } else { - Node node = mergeTwoDataEntriesIntoNode(owner, - k0, keyHash0, - k1, keyHash1, - shift + BIT_PARTITION_SIZE); - // values fit on next level - - int nodeMap = mask(bitpos0); - return NodeFactory.newBitmapIndexedNode(owner, nodeMap, (0), new Object[]{node}); - } - } - - abstract int dataArity(); - - /** - * Checks if this trie is equivalent to the specified other trie. - * - * @param other the other trie - * @return true if equivalent - */ - abstract boolean equivalent(@NonNull Object other); - - /** - * Finds a data object in the CHAMP trie, that matches the provided data - * object and data hash. - * - * @param data the provided data object - * @param dataHash the hash code of the provided data - * @param shift the shift for this node - * @param equalsFunction a function that tests data objects for equality - * @return the found data, returns {@link #NO_DATA} if no data in the trie - * matches the provided data. - */ - abstract Object find(D data, int dataHash, int shift, @NonNull BiPredicate equalsFunction); - - abstract @Nullable D getData(int index); - - @Nullable IdentityObject getOwner() { - return null; - } - - abstract @NonNull Node getNode(int index); - - /** - * Gets the node without de-referencing it. - */ - abstract @NonNull Object getNodeRaw(int index); - - abstract boolean hasData(); - - boolean isNodeEmpty() { - return !hasData() && !hasNodes(); - } - - boolean hasMany() { - return hasNodes() || dataArity() > 1; - } - - abstract boolean hasDataArityOne(); - - abstract boolean hasNodes(); - - boolean isAllowedToUpdate(@Nullable IdentityObject y) { - IdentityObject x = getOwner(); - return x != null && x == y; - } - - abstract int nodeArity(); - - /** - * Removes a data object from the trie. - * - * @param owner A non-null value means, that this method may update - * nodes that are marked with the same unique id, - * and that this method may create new mutable nodes - * with this unique id. - * A null value means, that this method must not update - * any node and may only create new immutable nodes. - * @param data the data to be removed - * @param dataHash the hash-code of the data object - * @param shift the shift of the current node - * @param details this method reports the changes that it performed - * in this object - * @param equalsFunction a function that tests data objects for equality - * @return the updated trie - */ - abstract @NonNull Node remove(@Nullable IdentityObject owner, D data, - int dataHash, int shift, - @NonNull ChangeEvent details, - @NonNull BiPredicate equalsFunction); - - /** - * Inserts or replaces a data object in the trie. - * - * @param owner A non-null value means, that this method may update - * nodes that are marked with the same unique id, - * and that this method may create new mutable nodes - * with this unique id. - * A null value means, that this method must not update - * any node and may only create new immutable nodes. - * @param newData the data to be inserted, - * or to be used for merging if there is already - * a matching data object in the trie - * @param dataHash the hash-code of the data object - * @param shift the shift of the current node - * @param details this method reports the changes that it performed - * in this object - * @return the updated trie - */ - abstract @NonNull Node put(@Nullable IdentityObject owner, D newData, - int dataHash, int shift, @NonNull ChangeEvent details, - @NonNull BiFunction updateFunction, - @NonNull BiPredicate equalsFunction, - @NonNull ToIntFunction hashFunction); - - /** - * Inserts or replaces data elements from the specified other trie in this trie. - * - * @param owner - * @param otherNode a node with the same shift as this node from the other trie - * @param shift the shift of this node and the other node - * @param bulkChange updates the field {@link BulkChangeEvent#inBoth} - * @param updateFunction the update function for data elements - * @param equalsFunction the equals function for data elements - * @param hashFunction the hash function for data elements - * @param details the change event for single elements - * @return the updated trie - */ - protected abstract @NonNull Node putAll(@Nullable IdentityObject owner, @NonNull Node otherNode, int shift, - @NonNull BulkChangeEvent bulkChange, - @NonNull BiFunction updateFunction, - @NonNull BiPredicate equalsFunction, - @NonNull ToIntFunction hashFunction, - @NonNull ChangeEvent details); - - /** - * Removes data elements in the specified other trie from this trie. - * - * @param owner - * @param otherNode a node with the same shift as this node from the other trie - * @param shift the shift of this node and the other node - * @param bulkChange updates the field {@link BulkChangeEvent#removed} - * @param updateFunction the update function for data elements - * @param equalsFunction the equals function for data elements - * @param hashFunction the hash function for data elements - * @param details the change event for single elements - * @return the updated trie - */ - protected abstract @NonNull Node removeAll(@Nullable IdentityObject owner, @NonNull Node otherNode, int shift, - @NonNull BulkChangeEvent bulkChange, - @NonNull BiFunction updateFunction, - @NonNull BiPredicate equalsFunction, - @NonNull ToIntFunction hashFunction, - @NonNull ChangeEvent details); - - /** - * Retains data elements in this trie that are also in the other trie - removes the rest. - * - * @param owner - * @param otherNode a node with the same shift as this node from the other trie - * @param shift the shift of this node and the other node - * @param bulkChange updates the field {@link BulkChangeEvent#removed} - * @param updateFunction the update function for data elements - * @param equalsFunction the equals function for data elements - * @param hashFunction the hash function for data elements - * @param details the change event for single elements - * @return the updated trie - */ - protected abstract @NonNull Node retainAll(@Nullable IdentityObject owner, @NonNull Node otherNode, int shift, - @NonNull BulkChangeEvent bulkChange, - @NonNull BiFunction updateFunction, - @NonNull BiPredicate equalsFunction, - @NonNull ToIntFunction hashFunction, - @NonNull ChangeEvent details); - - /** - * Retains data elements in this trie for which the provided predicate returns true. - * - * @param owner - * @param predicate a predicate that returns true for data elements that should be retained - * @param shift the shift of this node and the other node - * @param bulkChange updates the field {@link BulkChangeEvent#removed} - * @return the updated trie - */ - protected abstract @NonNull Node filterAll(@Nullable IdentityObject owner, Predicate predicate, int shift, - @NonNull BulkChangeEvent bulkChange); - - protected abstract int calculateSize(); -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/NodeFactory.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/NodeFactory.java deleted file mode 100644 index b16b94c19..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/NodeFactory.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * @(#)NodeFactory.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.impl.champ; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.impl.IdentityObject; - -/** - * Provides factory methods for {@link Node}s. - */ -class NodeFactory { - - /** - * Don't let anyone instantiate this class. - */ - private NodeFactory() { - } - - static @NonNull BitmapIndexedNode newBitmapIndexedNode( - @Nullable IdentityObject owner, int nodeMap, - int dataMap, @NonNull Object[] nodes) { - return owner == null - ? new BitmapIndexedNode<>(nodeMap, dataMap, nodes) - : new MutableBitmapIndexedNode<>(owner, nodeMap, dataMap, nodes); - } - - static @NonNull HashCollisionNode newHashCollisionNode( - @Nullable IdentityObject owner, int hash, @NonNull Object @NonNull [] entries) { - return owner == null - ? new HashCollisionNode<>(entries) - : new MutableHashCollisionNode<>(owner, entries); - } -} \ No newline at end of file diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/ReverseTombSkippingVectorSpliterator.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/ReverseTombSkippingVectorSpliterator.java deleted file mode 100644 index 1cf9a758f..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/ReverseTombSkippingVectorSpliterator.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * @(#)VectorSpliterator.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.impl.champ; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorList; - -import java.util.Spliterators; -import java.util.function.Consumer; -import java.util.function.Function; - -/** - * A spliterator for a {@code VectorMap} or {@code VectorSet} that skips - * tombstones. - * - * @param the element type - */ -public class ReverseTombSkippingVectorSpliterator extends Spliterators.AbstractSpliterator { - private final @NonNull VectorList vector; - private final @NonNull Function mapper; - private int index; - - public ReverseTombSkippingVectorSpliterator(@NonNull VectorList vector, @NonNull Function mapper, int additionalCharacteristics, long est) { - super(est, additionalCharacteristics); - this.vector = vector; - this.mapper = mapper; - index = vector.size() - 1; - } - - @Override - public boolean tryAdvance(Consumer action) { - if (index < 0) { - return false; - } - Object o = vector.get(index--); - if (o instanceof VectorTombstone t) { - index -= t.before(); - o = vector.get(index--); - } - action.accept(mapper.apply(o)); - return true; - } - -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/SequencedData.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/SequencedData.java deleted file mode 100644 index f9ec208ac..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/SequencedData.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * @(#)SequencedData.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.impl.champ; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.enumerator.SpliteratorEnumeratorWrapper; -import org.jhotdraw8.collection.impl.IdentityObject; -import org.jhotdraw8.collection.pair.OrderedPair; -import org.jhotdraw8.collection.pair.SimpleOrderedPair; - -import java.util.function.BiFunction; -import java.util.function.BiPredicate; -import java.util.function.ToIntFunction; - -/** - * A {@code SequencedData} stores a sequence number plus some data. - *

- * {@code SequencedData} objects are used to store sequenced data in a CHAMP - * trie (see {@link Node}). - *

- * The kind of data is specified in concrete implementations of this - * interface. - *

- * All sequence numbers of {@code SequencedData} objects in the same CHAMP trie - * are unique. Sequence numbers range from {@link Integer#MIN_VALUE} (exclusive) - * to {@link Integer#MAX_VALUE} (inclusive). - */ -public interface SequencedData { - /** - * We use {@link Integer#MIN_VALUE} to detect overflows in the sequence number. - *

- * {@link Integer#MIN_VALUE} is the only integer number which can not - * be negated. - *

- * Therefore, we can not use {@link Integer#MIN_VALUE} as a sequence number - * anyway. - */ - int NO_SEQUENCE_NUMBER = Integer.MIN_VALUE; - - - static boolean vecMustRenumber(int size, int offset, int vectorSize) { - return size == 0 - || vectorSize >>> 1 > size - || (long) vectorSize - offset > Integer.MAX_VALUE - 2 - || offset < Integer.MIN_VALUE + 2; - } - - /** - * Renumbers the sequence numbers in all nodes from {@code 0} to {@code size}. - *

- * Afterward, the sequence number for the next inserted entry must be - * set to the value {@code size}; - * - * @param - * @param owner - * @param size the size of the trie - * @param root the root of the trie - * @param vector the sequence root of the trie - * @param hashFunction the hash function for data elements - * @param equalsFunction the equals function for data elements - * @param factoryFunction the factory function for data elements - * @return a new renumbered root and a new vector with matching entries - */ - @SuppressWarnings("unchecked") - static OrderedPair, VectorList> vecRenumber( - @Nullable IdentityObject owner, int size, - @NonNull BitmapIndexedNode root, - @NonNull VectorList vector, - @NonNull ToIntFunction hashFunction, - @NonNull BiPredicate equalsFunction, - @NonNull BiFunction factoryFunction) { - if (size == 0) { - new SimpleOrderedPair<>(root, vector); - } - BitmapIndexedNode renumberedRoot = root; - VectorList renumberedVector = VectorList.of(); - ChangeEvent details = new ChangeEvent<>(); - BiFunction forceUpdate = (oldk, newk) -> newk; - int seq = 0; - for (var i = new SpliteratorEnumeratorWrapper(new TombSkippingVectorSpliterator(vector, o -> (K) o, 0, Long.MAX_VALUE, 0)); i.moveNext(); ) { - K current = i.current(); - K data = factoryFunction.apply(current, seq++); - renumberedVector = renumberedVector.add(data); - renumberedRoot = renumberedRoot.put(owner, data, hashFunction.applyAsInt(current), 0, details, forceUpdate, equalsFunction, hashFunction); - } - - return new SimpleOrderedPair<>(renumberedRoot, renumberedVector); - } - - - VectorTombstone TOMB_ZERO_ZERO = new VectorTombstone(0, 0); - - static OrderedPair, Integer> vecRemove(VectorList vector, K oldElem, int offset) { - // If the element is the first, we can remove it and its neighboring tombstones from the vector. - int size = vector.size(); - int index = oldElem.getSequenceNumber() + offset; - if (index == 0) { - if (size > 1) { - Object o = vector.get(1); - if (o instanceof VectorTombstone t) { - return new SimpleOrderedPair<>(vector.removeRange(0, 2 + t.after()), offset - 2 - t.after()); - } - } - return new SimpleOrderedPair<>(vector.removeFirst(), offset - 1); - } - - // If the element is the last , we can remove it and its neighboring tombstones from the vector. - if (index == size - 1) { - Object o = vector.get(size - 2); - if (o instanceof VectorTombstone t) { - return new SimpleOrderedPair<>(vector.removeRange(size - 2 - t.before(), size), offset); - } - return new SimpleOrderedPair<>(vector.removeLast(), offset); - } - - // Otherwise, we replace the element with a tombstone, and we update before/after skip counts - assert index > 0 && index < size - 1; - Object before = vector.get(index - 1); - Object after = vector.get(index + 1); - if (before instanceof VectorTombstone tb && after instanceof VectorTombstone ta) { - vector = vector.set(index - 1 - tb.before(), new VectorTombstone(0, 2 + tb.before() + ta.after())); - vector = vector.set(index, TOMB_ZERO_ZERO); - vector = vector.set(index + 1 + ta.after(), new VectorTombstone(2 + tb.before() + ta.after(), 0)); - } else if (before instanceof VectorTombstone tb) { - vector = vector.set(index - 1 - tb.before(), new VectorTombstone(0, 1 + tb.before())); - vector = vector.set(index, new VectorTombstone(1 + tb.before(), 0)); - } else if (after instanceof VectorTombstone ta) { - vector = vector.set(index, new VectorTombstone(0, 1 + ta.after())); - vector = vector.set(index + 1 + ta.after(), new VectorTombstone(1 + ta.after(), 0)); - } else { - vector = vector.set(index, TOMB_ZERO_ZERO); - } - assert !(vector.getFirst() instanceof VectorTombstone) && !(vector.getLast() instanceof VectorTombstone); - return new SimpleOrderedPair<>(vector, offset); - } - - /** - * Gets the sequence number of the data. - * - * @return sequence number in the range from {@link Integer#MIN_VALUE} - * (exclusive) to {@link Integer#MAX_VALUE} (inclusive). - */ - int getSequenceNumber(); - - -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/SequencedElement.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/SequencedElement.java deleted file mode 100644 index 4438532d8..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/SequencedElement.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * @(#)SequencedElement.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.impl.champ; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; - -import java.util.Objects; - -/** - * A {@code SequencedElement} stores an element of a set and a sequence number. - *

- * {@code hashCode} and {@code equals} are based on the element - the sequence - * number is not included. - */ -public class SequencedElement implements SequencedData { - - private final @Nullable E element; - private final int sequenceNumber; - - public SequencedElement(@Nullable E element) { - this.element = element; - this.sequenceNumber = NO_SEQUENCE_NUMBER; - } - - public SequencedElement(@Nullable E element, int sequenceNumber) { - this.element = element; - this.sequenceNumber = sequenceNumber; - } - - @NonNull - public static SequencedElement put(@NonNull SequencedElement oldK, @NonNull SequencedElement newK) { - return oldK; - } - - public static int keyHash(@Nullable Object a) { - return Objects.hashCode(a); - } - - public static int elementKeyHash(@NonNull SequencedElement a) { - return Objects.hashCode(a.getElement()); - } - - - @NonNull - public static SequencedElement putAndMoveToFirst(@NonNull SequencedElement oldK, @NonNull SequencedElement newK) { - return oldK.getSequenceNumber() == newK.getSequenceNumber() + 1 ? oldK : newK; - } - - @NonNull - public static SequencedElement putAndMoveToLast(@NonNull SequencedElement oldK, @NonNull SequencedElement newK) { - return oldK.getSequenceNumber() == newK.getSequenceNumber() - 1 ? oldK : newK; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - SequencedElement that = (SequencedElement) o; - return Objects.equals(element, that.element); - } - - @Override - public int hashCode() { - return Objects.hashCode(element); - } - - public @Nullable E getElement() { - return element; - } - - public int getSequenceNumber() { - return sequenceNumber; - } - - @Override - public String toString() { - return "{" + element + - ", seq=" + sequenceNumber + - '}'; - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/SequencedEntry.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/SequencedEntry.java deleted file mode 100644 index 1267fcbdc..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/SequencedEntry.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * @(#)SequencedEntry.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.impl.champ; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; - -import java.io.Serial; -import java.util.AbstractMap; -import java.util.Objects; - -/** - * A {@code SequencedEntry} stores an entry of a map and a sequence number. - *

- * {@code hashCode} and {@code equals} are based on the key and the value - * of the entry - the sequence number is not included. - */ -public class SequencedEntry extends AbstractMap.SimpleImmutableEntry - implements SequencedData { - @Serial - private static final long serialVersionUID = 0L; - private final int sequenceNumber; - - public SequencedEntry(@Nullable K key) { - super(key, null); - sequenceNumber = NO_SEQUENCE_NUMBER; - } - - public SequencedEntry(@Nullable K key, @Nullable V value, int sequenceNumber) { - super(key, value); - this.sequenceNumber = sequenceNumber; - } - - public static boolean keyEquals(@NonNull SequencedEntry a, @NonNull SequencedEntry b) { - return Objects.equals(a.getKey(), b.getKey()); - } - - public static int entryKeyHash(@NonNull SequencedEntry a) { - return Objects.hashCode(a.getKey()); - } - - public static int keyHash(@NonNull Object a) { - return Objects.hashCode(a); - } - - @NonNull - public static SequencedEntry update(@NonNull SequencedEntry oldK, @NonNull SequencedEntry newK) { - return Objects.equals(oldK.getValue(), newK.getValue()) ? oldK : - new SequencedEntry<>(oldK.getKey(), newK.getValue(), oldK.getSequenceNumber()); - } - - @NonNull - public static SequencedEntry updateAndMoveToFirst(@NonNull SequencedEntry oldK, @NonNull SequencedEntry newK) { - return Objects.equals(oldK.getValue(), newK.getValue()) - && oldK.getSequenceNumber() == newK.getSequenceNumber() + 1 - ? oldK - : newK.getSequenceNumber() == oldK.getSequenceNumber() - 1 - ? new SequencedEntry<>(oldK.getKey(), newK.getValue(), oldK.getSequenceNumber()) : newK; - } - - @NonNull - public static SequencedEntry updateAndMoveToLast(@NonNull SequencedEntry oldK, @NonNull SequencedEntry newK) { - return Objects.equals(oldK.getValue(), newK.getValue()) - && oldK.getSequenceNumber() == newK.getSequenceNumber() - 1 - ? oldK - : newK.getSequenceNumber() == oldK.getSequenceNumber() + 1 - ? new SequencedEntry<>(oldK.getKey(), newK.getValue(), oldK.getSequenceNumber()) : newK; - } - - public int getSequenceNumber() { - return sequenceNumber; - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/TombSkippingVectorSpliterator.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/TombSkippingVectorSpliterator.java deleted file mode 100644 index 0489e05f9..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/TombSkippingVectorSpliterator.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * @(#)VectorSpliterator.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.impl.champ; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.impl.vector.BitMappedTrie; - -import java.util.Spliterators; -import java.util.function.Consumer; -import java.util.function.Function; - -/** - * A spliterator for a {@code VectorMap} or {@code VectorSet} that skips - * tombstones. - * - * @param the key type - */ -public class TombSkippingVectorSpliterator extends Spliterators.AbstractSpliterator implements Consumer { - private final BitMappedTrie.@NonNull BitMappedTrieSpliterator vector; - private final @NonNull Function mapper; - private @Nullable Object current; - - public TombSkippingVectorSpliterator(@NonNull VectorList vector, @NonNull Function mapper, int fromIndex, long est, int additionalCharacteristics) { - super(est, additionalCharacteristics); - this.vector = new BitMappedTrie.BitMappedTrieSpliterator<>(vector, fromIndex, vector.size(), 0); - this.mapper = mapper; - } - - @Override - public boolean tryAdvance(Consumer action) { - boolean success = vector.tryAdvance(this); - if (!success) return false; - if (current instanceof VectorTombstone t) { - vector.skip(t.after()); - vector.tryAdvance(this); - } - action.accept(mapper.apply(current)); - return true; - } - - @Override - public void accept(Object o) { - current = o; - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/VectorTombstone.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/VectorTombstone.java deleted file mode 100644 index 9bd8c2ec7..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/VectorTombstone.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * @(#)Tombstone.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.impl.champ; - -import org.jhotdraw8.collection.VectorSet; - -/** - * A tombstone is used by {@link VectorSet} to mark a deleted slot in its Vector. - *

- * A tombstone stores the minimal number of neighbors 'before' and 'after' it in the - * Vector. - *

- * When we insert a new tombstone, we update 'before' and 'after' values only on - * the first and last tombstone of a sequence of tombstones. Therefore, a delete - * operation requires reading of up to 3 neighboring elements in the vector, and - * updates of up to 3 elements. - *

- * There are no tombstones at the first and last element of the vector. When we - * remove the first or last element of the vector, we remove the tombstones. - *

- * Example: Tombstones are shown as before.after. - *

- *
- *
- *                              Indices:  0   1   2   3   4   5   6   7   8   9
- * Initial situation:           Values:  'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j'
- *
- * Deletion of element 5:
- * - read elements at indices 4, 5, 6                    'e' 'f' 'g'
- * - notice that none of them are tombstones
- * - put tombstone 0.0 at index 5                            0.0
- *
- * After deletion of element 5:          'a' 'b' 'c' 'd' 'e' 0.0 'g' 'h' 'i' 'j'
- *
- * After deletion of element 7:          'a' 'b' 'c' 'd' 'e' 0.0 'g' 0.0 'i' 'j'
- *
- * Deletion of element 8:
- * - read elements at indices 7, 8, 9                                0.0 'i' 'j'
- * - notice that 7 is a tombstone 0.0
- * - put tombstones 0.1, 1.0 at indices 7 and 8
- *
- * After deletion of element 8:          'a' 'b' 'c' 'd' 'e' 0.0 'g' 0.1 1.0 'j'
- *
- * Deletion of element 6:
- * - read elements at indices 5, 6, 7                        0.0 'g' 0.1
- * - notice that two of them are tombstones
- * - put tombstones 0.3, 0.0, 3.0 at indices 5, 6 and 8
- *
- * After deletion of element 6:          'a' 'b' 'c' 'd' 'e' 0.3 0.0 0.1 3.0 'j'
- *
- * Deletion of the last element 9:
- * - read elements at index 8                                            3.0
- * - notice that it is a tombstone
- * - remove the last element and the neighboring tombstone sequence
- *
- * After deletion of element 9:          'a' 'b' 'c' 'd' 'e'
- * 
- * References: - *

- * The design of this class is inspired by 'VectorMap.scala'. - *

- *
VectorMap.scala - *
The Scala library. Copyright EPFL and Lightbend, Inc. Apache License 2.0.
- *
github.com - *
- *
- * - * @param before minimal number of neighboring tombstones before this one - * @param after minimal number of neighboring tombstones after this one - */ -public record VectorTombstone(int before, int after) { - -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/package-info.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/package-info.java deleted file mode 100644 index 2684fe2d6..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/champ/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * @(#)package-info.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -/** - * Provides collections which use a Compressed Hash-Array Mapped Prefix-tree - * (CHAMP) as their internal data structure. - *

- * References: - *

- *
Michael J. Steindorfer (2017). - * Efficient Immutable Collections.
- *
michael.steindorfer.name - * - *
The Capsule Hash Trie Collections Library. - *
Copyright (c) Michael Steindorfer. BSD-2-Clause License
- *
github.com - *
- */ -package org.jhotdraw8.collection.impl.champ; \ No newline at end of file diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/vector/ArrayType.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/vector/ArrayType.java deleted file mode 100644 index 6de5c070f..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/vector/ArrayType.java +++ /dev/null @@ -1,657 +0,0 @@ -/* - * @(#)ArrayType.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.impl.vector; - -/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*\ - G E N E R A T O R C R A F T E D -\*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ - -import java.io.Serial; -import java.io.Serializable; - -/** - * Helper to replace reflective array access. - *

- * References: - *

- * This class has been derived from 'vavr' ArrayType.java. - *

- *
ArrayType.java. Copyright 2023 (c) vavr. MIT License.
- *
github.com
- *
- */ -public interface ArrayType { - @SuppressWarnings("unchecked") - static ArrayType obj() { - return (ArrayType) ObjectArrayType.INSTANCE; - } - - Class type(); - - int lengthOf(Object array); - - T getAt(Object array, int index); - - Object empty(); - - void setAt(Object array, int index, T value) throws ClassCastException; - - Object copy(Object array, int arraySize, int sourceFrom, int destinationFrom, int size); - - @SuppressWarnings("unchecked") - static ArrayType of(Object array) { - return of((Class) array.getClass().getComponentType()); - } - - static ArrayType of(Class type) { - return !type.isPrimitive() ? obj() : ofPrimitive(type); - } - - @SuppressWarnings("unchecked") - static ArrayType ofPrimitive(Class type) { - if (boolean.class == type) { - return (ArrayType) BooleanArrayType.INSTANCE; - } else if (byte.class == type) { - return (ArrayType) ByteArrayType.INSTANCE; - } else if (char.class == type) { - return (ArrayType) CharArrayType.INSTANCE; - } else if (double.class == type) { - return (ArrayType) DoubleArrayType.INSTANCE; - } else if (float.class == type) { - return (ArrayType) FloatArrayType.INSTANCE; - } else if (int.class == type) { - return (ArrayType) IntArrayType.INSTANCE; - } else if (long.class == type) { - return (ArrayType) LongArrayType.INSTANCE; - } else if (short.class == type) { - return (ArrayType) ShortArrayType.INSTANCE; - } else { - throw new IllegalArgumentException(String.valueOf(type)); - } - } - - default Object newInstance(int length) { - return copy(empty(), length); - } - - /** - * Creates a new array that contains the specified - * range of elements from the provided array. - * - * @param array the array - * @param from the first index (inclusive) - * @param to the last index (exclusive) - * @return a new array - */ - default Object copyRange(Object array, int from, int to) { - final int length = to - from; - return copy(array, length, from, 0, length); - } - - /** - * Repeatedly group an array into equal sized subtrees. - * - * @param array an array - * @param groupSize the group size - * @return a new array of arrays - */ - default Object grouped(Object array, int groupSize) { - final int arrayLength = lengthOf(array); - final Object results = obj().newInstance(1 + ((arrayLength - 1) / groupSize)); - obj().setAt(results, 0, copyRange(array, 0, groupSize)); - - for (int start = groupSize, i = 1; start < arrayLength; i++) { - final int nextLength = Math.min(groupSize, arrayLength - (i * groupSize)); - obj().setAt(results, i, copyRange(array, start, start + nextLength)); - start += nextLength; - } - - return results; - } - - /** - * Clone the source and set the value at the given position. - * - * @param array an array - * @param index the position - * @param element the value to be set at the position - * @return a new array - */ - default Object copyUpdate(Object array, int index, T element) { - final Object copy = copy(array, index + 1); - setAt(copy, index, element); - return copy; - } - - default Object copy(Object array, int minLength) { - final int arrayLength = lengthOf(array); - final int length = Math.max(arrayLength, minLength); - return copy(array, length, 0, 0, arrayLength); - } - - /** - * Clone the source and keep everything after the index (pre-padding the values with null). - * - * @param array an array - * @param index the position to be removed - * @return a new array - */ - default Object copyDrop(Object array, int index) { - final int length = lengthOf(array); - return copy(array, length, index, index, length - index); - } - - /** - * Clone the source and keep everything before and including the index. - * - * @param array an array - * @param lastIndex the last position to be kept (inclusive) - * @return a new array - */ - default Object copyTake(Object array, int lastIndex) { - return copyRange(array, 0, lastIndex + 1); - } - - /** - * Create a single element array - * - * @param element an element - * @return a new array - */ - default Object asArray(T element) { - final Object result = newInstance(1); - setAt(result, 0, element); - return result; - } - - /** - * Store the content of an iterator in an array - * - * @param it an iterator - * @param length the desired array length - * @return a new array - */ - static Object[] asArray(java.util.Iterator it, int length) { - final Object[] array = new Object[length]; - for (int i = 0; i < length; i++) { - array[i] = it.next(); - } - return array; - } - - - final class BooleanArrayType implements ArrayType, Serializable { - @Serial - private static final long serialVersionUID = 1L; - static final BooleanArrayType INSTANCE = new BooleanArrayType(); - static final boolean[] EMPTY = new boolean[0]; - - private static boolean[] cast(Object array) { - return (boolean[]) array; - } - - @Override - public Class type() { - return boolean.class; - } - - @Override - public boolean[] empty() { - return EMPTY; - } - - @Override - public int lengthOf(Object array) { - return (array != null) ? cast(array).length : 0; - } - - @Override - public Boolean getAt(Object array, int index) { - return cast(array)[index]; - } - - @Override - public void setAt(Object array, int index, Boolean value) throws ClassCastException { - if (value != null) { - cast(array)[index] = value; - } else { - throw new ClassCastException(); - } - } - - @Override - public Object copy(Object array, int arraySize, int sourceFrom, int destinationFrom, int size) { - return (size > 0) - ? copyNonEmpty(array, arraySize, sourceFrom, destinationFrom, size) - : new boolean[arraySize]; - } - - private static Object copyNonEmpty(Object array, int arraySize, int sourceFrom, int destinationFrom, int size) { - final boolean[] result = new boolean[arraySize]; - System.arraycopy(array, sourceFrom, result, destinationFrom, size); /* has to be near the object allocation to avoid zeroing out the array */ - return result; - } - } - - final class ByteArrayType implements ArrayType, Serializable { - @Serial - private static final long serialVersionUID = 1L; - static final ByteArrayType INSTANCE = new ByteArrayType(); - static final byte[] EMPTY = new byte[0]; - - private static byte[] cast(Object array) { - return (byte[]) array; - } - - @Override - public Class type() { - return byte.class; - } - - @Override - public byte[] empty() { - return EMPTY; - } - - @Override - public int lengthOf(Object array) { - return (array != null) ? cast(array).length : 0; - } - - @Override - public Byte getAt(Object array, int index) { - return cast(array)[index]; - } - - @Override - public void setAt(Object array, int index, Byte value) throws ClassCastException { - if (value != null) { - cast(array)[index] = value; - } else { - throw new ClassCastException(); - } - } - - @Override - public Object copy(Object array, int arraySize, int sourceFrom, int destinationFrom, int size) { - return (size > 0) - ? copyNonEmpty(array, arraySize, sourceFrom, destinationFrom, size) - : new byte[arraySize]; - } - - private static Object copyNonEmpty(Object array, int arraySize, int sourceFrom, int destinationFrom, int size) { - final byte[] result = new byte[arraySize]; - System.arraycopy(array, sourceFrom, result, destinationFrom, size); /* has to be near the object allocation to avoid zeroing out the array */ - return result; - } - } - - final class CharArrayType implements ArrayType, Serializable { - @Serial - private static final long serialVersionUID = 1L; - static final CharArrayType INSTANCE = new CharArrayType(); - static final char[] EMPTY = new char[0]; - - private static char[] cast(Object array) { - return (char[]) array; - } - - @Override - public Class type() { - return char.class; - } - - @Override - public char[] empty() { - return EMPTY; - } - - @Override - public int lengthOf(Object array) { - return (array != null) ? cast(array).length : 0; - } - - @Override - public Character getAt(Object array, int index) { - return cast(array)[index]; - } - - @Override - public void setAt(Object array, int index, Character value) throws ClassCastException { - if (value != null) { - cast(array)[index] = value; - } else { - throw new ClassCastException(); - } - } - - @Override - public Object copy(Object array, int arraySize, int sourceFrom, int destinationFrom, int size) { - return (size > 0) - ? copyNonEmpty(array, arraySize, sourceFrom, destinationFrom, size) - : new char[arraySize]; - } - - private static Object copyNonEmpty(Object array, int arraySize, int sourceFrom, int destinationFrom, int size) { - final char[] result = new char[arraySize]; - System.arraycopy(array, sourceFrom, result, destinationFrom, size); /* has to be near the object allocation to avoid zeroing out the array */ - return result; - } - } - - final class DoubleArrayType implements ArrayType, Serializable { - @Serial - private static final long serialVersionUID = 1L; - static final DoubleArrayType INSTANCE = new DoubleArrayType(); - static final double[] EMPTY = new double[0]; - - private static double[] cast(Object array) { - return (double[]) array; - } - - @Override - public Class type() { - return double.class; - } - - @Override - public double[] empty() { - return EMPTY; - } - - @Override - public int lengthOf(Object array) { - return (array != null) ? cast(array).length : 0; - } - - @Override - public Double getAt(Object array, int index) { - return cast(array)[index]; - } - - @Override - public void setAt(Object array, int index, Double value) throws ClassCastException { - if (value != null) { - cast(array)[index] = value; - } else { - throw new ClassCastException(); - } - } - - @Override - public Object copy(Object array, int arraySize, int sourceFrom, int destinationFrom, int size) { - return (size > 0) - ? copyNonEmpty(array, arraySize, sourceFrom, destinationFrom, size) - : new double[arraySize]; - } - - private static Object copyNonEmpty(Object array, int arraySize, int sourceFrom, int destinationFrom, int size) { - final double[] result = new double[arraySize]; - System.arraycopy(array, sourceFrom, result, destinationFrom, size); /* has to be near the object allocation to avoid zeroing out the array */ - return result; - } - } - - final class FloatArrayType implements ArrayType, Serializable { - @Serial - private static final long serialVersionUID = 1L; - static final FloatArrayType INSTANCE = new FloatArrayType(); - static final float[] EMPTY = new float[0]; - - private static float[] cast(Object array) { - return (float[]) array; - } - - @Override - public Class type() { - return float.class; - } - - @Override - public float[] empty() { - return EMPTY; - } - - @Override - public int lengthOf(Object array) { - return (array != null) ? cast(array).length : 0; - } - - @Override - public Float getAt(Object array, int index) { - return cast(array)[index]; - } - - @Override - public void setAt(Object array, int index, Float value) throws ClassCastException { - if (value != null) { - cast(array)[index] = value; - } else { - throw new ClassCastException(); - } - } - - @Override - public Object copy(Object array, int arraySize, int sourceFrom, int destinationFrom, int size) { - return (size > 0) - ? copyNonEmpty(array, arraySize, sourceFrom, destinationFrom, size) - : new float[arraySize]; - } - - private static Object copyNonEmpty(Object array, int arraySize, int sourceFrom, int destinationFrom, int size) { - final float[] result = new float[arraySize]; - System.arraycopy(array, sourceFrom, result, destinationFrom, size); /* has to be near the object allocation to avoid zeroing out the array */ - return result; - } - } - - final class IntArrayType implements ArrayType, Serializable { - @Serial - private static final long serialVersionUID = 1L; - static final IntArrayType INSTANCE = new IntArrayType(); - static final int[] EMPTY = new int[0]; - - private static int[] cast(Object array) { - return (int[]) array; - } - - @Override - public Class type() { - return int.class; - } - - @Override - public int[] empty() { - return EMPTY; - } - - @Override - public int lengthOf(Object array) { - return (array != null) ? cast(array).length : 0; - } - - @Override - public Integer getAt(Object array, int index) { - return cast(array)[index]; - } - - @Override - public void setAt(Object array, int index, Integer value) throws ClassCastException { - if (value != null) { - cast(array)[index] = value; - } else { - throw new ClassCastException(); - } - } - - @Override - public Object copy(Object array, int arraySize, int sourceFrom, int destinationFrom, int size) { - return (size > 0) - ? copyNonEmpty(array, arraySize, sourceFrom, destinationFrom, size) - : new int[arraySize]; - } - - private static Object copyNonEmpty(Object array, int arraySize, int sourceFrom, int destinationFrom, int size) { - final int[] result = new int[arraySize]; - System.arraycopy(array, sourceFrom, result, destinationFrom, size); /* has to be near the object allocation to avoid zeroing out the array */ - return result; - } - } - - final class LongArrayType implements ArrayType, Serializable { - @Serial - private static final long serialVersionUID = 1L; - static final LongArrayType INSTANCE = new LongArrayType(); - static final long[] EMPTY = new long[0]; - - private static long[] cast(Object array) { - return (long[]) array; - } - - @Override - public Class type() { - return long.class; - } - - @Override - public long[] empty() { - return EMPTY; - } - - @Override - public int lengthOf(Object array) { - return (array != null) ? cast(array).length : 0; - } - - @Override - public Long getAt(Object array, int index) { - return cast(array)[index]; - } - - @Override - public void setAt(Object array, int index, Long value) throws ClassCastException { - if (value != null) { - cast(array)[index] = value; - } else { - throw new ClassCastException(); - } - } - - @Override - public Object copy(Object array, int arraySize, int sourceFrom, int destinationFrom, int size) { - return (size > 0) - ? copyNonEmpty(array, arraySize, sourceFrom, destinationFrom, size) - : new long[arraySize]; - } - - private static Object copyNonEmpty(Object array, int arraySize, int sourceFrom, int destinationFrom, int size) { - final long[] result = new long[arraySize]; - System.arraycopy(array, sourceFrom, result, destinationFrom, size); /* has to be near the object allocation to avoid zeroing out the array */ - return result; - } - } - - final class ShortArrayType implements ArrayType, Serializable { - @Serial - private static final long serialVersionUID = 1L; - static final ShortArrayType INSTANCE = new ShortArrayType(); - static final short[] EMPTY = new short[0]; - - private static short[] cast(Object array) { - return (short[]) array; - } - - @Override - public Class type() { - return short.class; - } - - @Override - public short[] empty() { - return EMPTY; - } - - @Override - public int lengthOf(Object array) { - return (array != null) ? cast(array).length : 0; - } - - @Override - public Short getAt(Object array, int index) { - return cast(array)[index]; - } - - @Override - public void setAt(Object array, int index, Short value) throws ClassCastException { - if (value != null) { - cast(array)[index] = value; - } else { - throw new ClassCastException(); - } - } - - @Override - public Object copy(Object array, int arraySize, int sourceFrom, int destinationFrom, int size) { - return (size > 0) - ? copyNonEmpty(array, arraySize, sourceFrom, destinationFrom, size) - : new short[arraySize]; - } - - private static Object copyNonEmpty(Object array, int arraySize, int sourceFrom, int destinationFrom, int size) { - final short[] result = new short[arraySize]; - System.arraycopy(array, sourceFrom, result, destinationFrom, size); /* has to be near the object allocation to avoid zeroing out the array */ - return result; - } - } - - final class ObjectArrayType implements ArrayType, Serializable { - @Serial - private static final long serialVersionUID = 1L; - static final ObjectArrayType INSTANCE = new ObjectArrayType(); - static final Object[] EMPTY = new Object[0]; - - private static Object[] cast(Object array) { - return (Object[]) array; - } - - @Override - public Class type() { - return Object.class; - } - - @Override - public Object[] empty() { - return EMPTY; - } - - @Override - public int lengthOf(Object array) { - return (array != null) ? cast(array).length : 0; - } - - @Override - public Object getAt(Object array, int index) { - return cast(array)[index]; - } - - @Override - public void setAt(Object array, int index, Object value) { - cast(array)[index] = value; - } - - @Override - public Object copy(Object array, int arraySize, int sourceFrom, int destinationFrom, int size) { - return (size > 0) - ? copyNonEmpty(array, arraySize, sourceFrom, destinationFrom, size) - : new Object[arraySize]; - } - - private static Object copyNonEmpty(Object array, int arraySize, int sourceFrom, int destinationFrom, int size) { - final Object[] result = new Object[arraySize]; - System.arraycopy(array, sourceFrom, result, destinationFrom, size); /* has to be near the object allocation to avoid zeroing out the array */ - return result; - } - } -} \ No newline at end of file diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/vector/BitMappedTrie.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/vector/BitMappedTrie.java deleted file mode 100644 index cdb10f9fe..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/vector/BitMappedTrie.java +++ /dev/null @@ -1,578 +0,0 @@ -/* - * @(#)BitMappedTrie.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - - -package org.jhotdraw8.collection.impl.vector; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.readonly.ReadOnlyCollection; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedCollection; -import org.jhotdraw8.collection.sequenced.SequencedCollection; - -import java.io.Serial; -import java.io.Serializable; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.NoSuchElementException; -import java.util.Spliterator; -import java.util.Spliterators; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Predicate; - -import static java.util.function.Function.identity; -import static org.jhotdraw8.collection.impl.vector.ArrayType.obj; - -/** - * A `bit-mapped trie` is a very wide and shallow tree (for integer indices the depth will be `≤6`). - *

- * Each node has a maximum of `32` children (configurable). - *

- * Access to a given position is done by converting the index to a base 32 number and using each digit to descend down - * the tree. - *

- * Modifying the tree is done similarly, but along the way the path is copied, returning a new root every time. - *

- * `Append` inserts in the last leaf, or if the tree is full from the right, it adds another layer on top of it - * (the old root will be the first of the new one). - *

- * `Prepend` is done similarly, but an offset is needed, because adding a new top node (where the current root would be - * the last node of the new root) shifts the indices by half of the current tree's full size. The `offset` shifts them - * back to the correct index. - *

- * `Slice` is done by trimming the path from the root and discarding any `leading`/`trailing` values in effectively - * constant time (without memory leak, as in `Java`/`Clojure`). - *

- * References: - *

- * This class has been derived from 'vavr' BitMappedTrie.java. - *

- *
Vector.java. Copyright 2023 (c) vavr. MIT License.
- *
github.com
- *
- */ -public class BitMappedTrie implements Serializable { - - static final int BRANCHING_BASE = 5; - static final int BRANCHING_FACTOR = 1 << BRANCHING_BASE; - static final int BRANCHING_MASK = -1 >>> -BRANCHING_BASE; - - static int firstDigit(int num, int depthShift) { - return num >> depthShift; - } - - static int digit(int num, int depthShift) { - return lastDigit(firstDigit(num, depthShift)); - } - - static int lastDigit(int num) { - return num & BRANCHING_MASK; - } - - @Serial - private static final long serialVersionUID = 1L; - - private static final @NonNull BitMappedTrie EMPTY = new BitMappedTrie<>(obj(), obj().empty(), 0, 0, 0); - - @SuppressWarnings("unchecked") - public static @NonNull BitMappedTrie empty() { - return (BitMappedTrie) EMPTY; - } - - public final @NonNull ArrayType type; - public final @NonNull Object array; - public final int offset; - public final int length; - public final int depthShift; - - protected BitMappedTrie(@NonNull ArrayType type, @NonNull Object array, int offset, int length, int depthShift) { - this.type = type; - this.array = array; - this.offset = offset; - this.length = length; - this.depthShift = depthShift; - } - - private static int treeSize(int branchCount, int depthShift) { - final int fullBranchSize = 1 << depthShift; - return branchCount * fullBranchSize; - } - - protected static @NonNull BitMappedTrie ofAll(@NonNull Object array) { - final ArrayType type = ArrayType.of(array); - final int size = type.lengthOf(array); - return (size == 0) ? empty() : ofAll(array, type, size); - } - - private static @NonNull BitMappedTrie ofAll(@NonNull Object array, @NonNull ArrayType type, int size) { - int shift = 0; - for (ArrayType t = type; t.lengthOf(array) > BRANCHING_FACTOR; shift += BRANCHING_BASE) { - array = t.grouped(array, BRANCHING_FACTOR); - t = obj(); - } - return new BitMappedTrie<>(type, array, 0, size, shift); - } - - private @NonNull BitMappedTrie boxed() { - return map(identity()); - } - - @SuppressWarnings("unchecked") - @NonNull - protected BitMappedTrie prependAll(@NonNull Iterable iterable) { - if (iterable instanceof SequencedCollection s) { - return prepend((Iterator) s._reversed().iterator(), s.size()); - } - if (iterable instanceof ReadOnlySequencedCollection c) { - return append(iterable.iterator(), c.size()); - } - - BitMappedTrie result = this; - for (T t : iterable) { - result = result.prepend(Collections.singleton(t).iterator(), 1); - } - return result; - } - - @NonNull - public BitMappedTrie prepend(java.util.@NonNull Iterator iterator, int size) { - BitMappedTrie result = this; - while (size > 0) { - Object array = result.array; - int shift = result.depthShift, offset = result.offset; - if (result.isFullLeft()) { - array = obj().copyUpdate(obj().empty(), BRANCHING_FACTOR - 1, array); - shift += BRANCHING_BASE; - offset = treeSize(BRANCHING_FACTOR - 1, shift); - } - - final int index = offset - 1; - final int delta = Math.min(size, lastDigit(index) + 1); - size -= delta; - - array = result.modify(array, shift, index, NodeModifier.COPY_NODE, prependToLeaf(iterator)); - result = new BitMappedTrie<>(type, array, offset - delta, result.length + delta, shift); - } - return result; - } - - @NonNull - public BitMappedTrie prepend(@Nullable T t) { - BitMappedTrie result = this; - int size = 1; - while (size > 0) { - Object array = result.array; - int shift = result.depthShift, offset = result.offset; - if (result.isFullLeft()) { - array = obj().copyUpdate(obj().empty(), BRANCHING_FACTOR - 1, array); - shift += BRANCHING_BASE; - offset = treeSize(BRANCHING_FACTOR - 1, shift); - } - - final int index = offset - 1; - final int delta = Math.min(1, lastDigit(index) + 1); - size -= delta; - - array = result.modify(array, shift, index, NodeModifier.COPY_NODE, prependToLeaf(t)); - result = new BitMappedTrie<>(type, array, offset - delta, result.length + delta, shift); - } - return result; - } - - private boolean isFullLeft() { - return offset == 0; - } - - private @NonNull NodeModifier prependToLeaf(java.util.@NonNull Iterator iterator) { - return (array, index) -> { - final Object copy = type.copy(array, BRANCHING_FACTOR); - while (iterator.hasNext() && index >= 0) { - type.setAt(copy, index--, iterator.next()); - } - return copy; - }; - } - - private @NonNull NodeModifier prependToLeaf(@Nullable T t) { - return (array, index) -> { - final Object copy = type.copy(array, BRANCHING_FACTOR); - type.setAt(copy, index, t); - return copy; - }; - } - - @NonNull - public BitMappedTrie appendAll(@NonNull Iterable iterable) { - if (iterable instanceof Collection c) { - return append(iterable.iterator(), c.size()); - } - if (iterable instanceof ReadOnlyCollection c) { - return append(iterable.iterator(), c.size()); - } - BitMappedTrie result = this; - for (T t : iterable) { - result = result.append(Collections.singleton(t).iterator(), 1); - } - return result; - } - - @NonNull - public BitMappedTrie append(java.util.@NonNull Iterator iterator, int size) { - BitMappedTrie result = this; - while (size > 0) { - Object array = result.array; - int shift = result.depthShift; - if (result.isFullRight()) { - array = obj().asArray(array); - shift += BRANCHING_BASE; - } - - final int index = offset + result.length; - final int leafSpace = lastDigit(index); - final int delta = Math.min(size, BRANCHING_FACTOR - leafSpace); - size -= delta; - - array = result.modify(array, shift, index, NodeModifier.COPY_NODE, appendToLeaf(iterator, leafSpace + delta)); - result = new BitMappedTrie<>(type, array, offset, result.length + delta, shift); - } - return result; - } - - @NonNull - public BitMappedTrie append(@Nullable T element) { - BitMappedTrie result = this; - int size = 1; - while (size > 0) { - Object array = result.array; - int shift = result.depthShift; - if (result.isFullRight()) { - array = obj().asArray(array); - shift += BRANCHING_BASE; - } - - final int index = offset + result.length; - final int leafSpace = lastDigit(index); - final int delta = Math.min(size, BRANCHING_FACTOR - leafSpace); - size -= delta; - - array = result.modify(array, shift, index, NodeModifier.COPY_NODE, appendToLeaf(element, leafSpace + delta)); - result = new BitMappedTrie<>(type, array, offset, result.length + delta, shift); - } - return result; - } - - private boolean isFullRight() { - return (offset + length + 1) > treeSize(BRANCHING_FACTOR, depthShift); - } - - private @NonNull NodeModifier appendToLeaf(java.util.@NonNull Iterator iterator, int leafSize) { - return (array, index) -> { - final Object copy = type.copy(array, leafSize); - while (iterator.hasNext() && index < leafSize) { - type.setAt(copy, index++, iterator.next()); - } - return copy; - }; - } - - private @NonNull NodeModifier appendToLeaf(T element, int leafSize) { - return (array, index) -> { - final Object copy = type.copy(array, leafSize); - if (index < leafSize) { - type.setAt(copy, index, element); - } - return copy; - }; - } - - @NonNull - public BitMappedTrie update(int index, @Nullable T element) { - try { - final Object root = modify(array, depthShift, offset + index, NodeModifier.COPY_NODE, updateLeafWith(type, element)); - return new BitMappedTrie<>(type, root, offset, length, depthShift); - } catch (ClassCastException ignored) { - return boxed().update(index, element); - } - } - - private @NonNull NodeModifier updateLeafWith(ArrayType type, @Nullable T element) { - return (a, i) -> type.copyUpdate(a, i, element); - } - - @NonNull - public BitMappedTrie drop(int n) { - if (n <= 0) { - return this; - } else if (n >= length) { - return empty(); - } else { - final int index = offset + n; - final Object root = arePointingToSameLeaf(0, n) - ? array - : modify(array, depthShift, index, obj()::copyDrop, NodeModifier.IDENTITY); - return collapsed(type, root, index, length - n, depthShift); - } - } - - @NonNull - public BitMappedTrie take(int n) { - if (n >= length) { - return this; - } else if (n <= 0) { - return empty(); - } else { - final int index = n - 1; - final Object root = arePointingToSameLeaf(index, length - 1) - ? array - : modify(array, depthShift, offset + index, obj()::copyTake, NodeModifier.IDENTITY); - return collapsed(type, root, offset, n, depthShift); - } - } - - private boolean arePointingToSameLeaf(int i, int j) { - return firstDigit(offset + i, BRANCHING_BASE) == firstDigit(offset + j, BRANCHING_BASE); - } - - /* drop root node while it has a single element */ - private static @NonNull BitMappedTrie collapsed(@NonNull ArrayType type, Object array, int offset, int length, int shift) { - for (; shift > 0; shift -= BRANCHING_BASE) { - final int skippedElements = obj().lengthOf(array) - 1; - if (skippedElements != digit(offset, shift)) { - break; - } - array = obj().getAt(array, skippedElements); - offset -= treeSize(skippedElements, shift); - } - return new BitMappedTrie<>(type, array, offset, length, shift); - } - - /* descend the tree from root to leaf, applying the given modifications along the way, returning the new root */ - private @NonNull Object modify(@NonNull Object root, int depthShift, int index, @NonNull NodeModifier node, @NonNull NodeModifier leaf) { - return (depthShift == 0) - ? leaf.apply(root, index) - : modifyNonLeaf(root, depthShift, index, node, leaf); - } - - private @NonNull Object modifyNonLeaf(@NonNull Object root, int depthShift, int index, @NonNull NodeModifier node, @NonNull NodeModifier leaf) { - int previousIndex = firstDigit(index, depthShift); - root = node.apply(root, previousIndex); - - Object array = root; - for (int shift = depthShift - BRANCHING_BASE; shift >= BRANCHING_BASE; shift -= BRANCHING_BASE) { - final int prev = previousIndex; - previousIndex = digit(index, shift); - array = setNewNode(node, prev, array, previousIndex); - } - - final Object newLeaf = leaf.apply(obj().getAt(array, previousIndex), lastDigit(index)); - obj().setAt(array, previousIndex, newLeaf); - return root; - } - - private @NonNull Object setNewNode(@NonNull NodeModifier node, int previousIndex, @NonNull Object array, int offset) { - final Object previous = obj().getAt(array, previousIndex); - final Object newNode = node.apply(previous, offset); - obj().setAt(array, previousIndex, newNode); - return newNode; - } - - @Nullable - public T get(int index) { - final Object leaf = getLeaf(index); - final int leafIndex = lastDigit(offset + index); - return type.getAt(leaf, leafIndex); - } - - /** - * fetch the leaf, corresponding to the given index. - * Node: the offset and length should be taken into consideration as there may be leading and trailing garbage. - * Also, the returned array is mutable, but should not be mutated! - */ - @SuppressWarnings("WeakerAccess") - @Nullable Object getLeaf(int index) { - if (depthShift == 0) { - return array; - } else { - return getLeafGeneral(index); - } - } - - private @Nullable Object getLeafGeneral(int index) { - index += offset; - Object leaf = obj().getAt(array, firstDigit(index, depthShift)); - for (int shift = depthShift - BRANCHING_BASE; shift > 0; shift -= BRANCHING_BASE) { - leaf = obj().getAt(leaf, digit(index, shift)); - } - return leaf; - } - - - public @NonNull Spliterator spliterator(int fromIndex, int toIndex, int characteristics) { - return new BitMappedTrieSpliterator<>(this, fromIndex, toIndex, characteristics); - } - - @NonNull - public Iterator iterator(int fromIndex, int toIndex) { - return new BitMappedTrieIterator<>(this, fromIndex, toIndex); - } - - @NonNull - public Iterator iterator() { - return new BitMappedTrieIterator<>(this, 0, length); - } - - public static class BitMappedTrieSpliterator extends Spliterators.AbstractSpliterator { - private final int globalLength; - private int globalIndex; - - private int index; - private Object leaf; - private int length; - private final @NonNull BitMappedTrie root; - - public BitMappedTrieSpliterator(@NonNull BitMappedTrie root, int fromIndex, int toIndex, int characteristics) { - super(root.length - fromIndex, characteristics); - this.root = root; - globalLength = toIndex; - globalIndex = fromIndex; - index = lastDigit(root.offset + globalIndex); - leaf = root.getLeaf(globalIndex); - length = root.type.lengthOf(leaf); - } - - @Override - public boolean tryAdvance(@NonNull Consumer action) { - if (globalIndex >= globalLength) { - return false; - } - if (index == length) { - setCurrentArray(); - } - var current = root.type.getAt(leaf, index); - index++; - globalIndex++; - action.accept(current); - return true; - } - - public void skip(int count) { - globalIndex += count; - index = lastDigit(root.offset + globalIndex); - leaf = root.getLeaf(globalIndex); - length = root.type.lengthOf(leaf); - } - - private void setCurrentArray() { - index = 0; - leaf = root.getLeaf(globalIndex); - length = root.type.lengthOf(leaf); - } - - } - - private static class BitMappedTrieIterator implements Iterator { - private final int globalLength; - private int globalIndex; - - private int index; - private Object leaf; - private int length; - private final @NonNull BitMappedTrie root; - - public BitMappedTrieIterator(@NonNull BitMappedTrie root, int fromIndex, int toIndex) { - this.root = root; - globalLength = toIndex; - globalIndex = fromIndex; - index = lastDigit(root.offset + fromIndex); - leaf = root.getLeaf(globalIndex); - length = root.type.lengthOf(leaf); - } - - @Override - public boolean hasNext() { - return globalIndex < globalLength; - } - - @Override - public T next() { - if (!hasNext()) { - throw new NoSuchElementException("next() on empty iterator"); - } - - if (index == length) { - setCurrentArray(); - } - final T next = root.type.getAt(leaf, index); - - index++; - globalIndex++; - - return next; - } - - private void setCurrentArray() { - index = 0; - leaf = root.getLeaf(globalIndex); - length = root.type.lengthOf(leaf); - } - } - - @SuppressWarnings("unchecked") - int visit(@NonNull LeafVisitor visitor) { - int globalIndex = 0, start = lastDigit(offset); - for (int index = 0; index < length; ) { - final T2 leaf = (T2) getLeaf(index); - final int end = getMin(start, index, leaf); - - globalIndex = visitor.visit(globalIndex, leaf, start, end); - - index += end - start; - start = 0; - } - return globalIndex; - } - - private int getMin(int start, int index, @Nullable Object leaf) { - return Math.min(type.lengthOf(leaf), start + length - index); - } - - @NonNull BitMappedTrie filter(@NonNull Predicate predicate) { - final Object results = type.newInstance(length()); - final int length = this.visit((index, leaf, start, end) -> filter(predicate, results, index, leaf, start, end)); - return (this.length == length) - ? this - : BitMappedTrie.ofAll(type.copyRange(results, 0, length)); - } - - private int filter(@NonNull Predicate predicate, @NonNull Object results, int index, T leaf, int start, int end) { - for (int i = start; i < end; i++) { - final T value = type.getAt(leaf, i); - if (predicate.test(value)) { - type.setAt(results, index++, value); - } - } - return index; - } - - @NonNull BitMappedTrie map(@NonNull Function mapper) { - final Object results = obj().newInstance(length); - this.visit((index, leaf, start, end) -> map(mapper, results, index, leaf, start, end)); - return BitMappedTrie.ofAll(results); - } - - private int map(@NonNull Function mapper, @NonNull Object results, int index, @Nullable T leaf, int start, int end) { - for (int i = start; i < end; i++) { - obj().setAt(results, index++, mapper.apply(type.getAt(leaf, i))); - } - return index; - } - - public int length() { - return length; - } -} - diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/vector/LeafVisitor.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/vector/LeafVisitor.java deleted file mode 100644 index 0bbb0f7ba..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/vector/LeafVisitor.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * @(#)LeafVisitor.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.impl.vector; - -/** - * LeafVisitor. - *

- * References: - *

- * This class has been derived from 'vavr' BitMappedTrie.java. - *

- *
Vector.java. Copyright 2023 (c) vavr. MIT License.
- *
github.com
- *
- * - * @param data type - */ -@FunctionalInterface -interface LeafVisitor { - int visit(int index, T leaf, int start, int end); -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/vector/NodeModifier.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/vector/NodeModifier.java deleted file mode 100644 index 2fbff49d2..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/impl/vector/NodeModifier.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * @(#)NodeModifier.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.impl.vector; - -import static org.jhotdraw8.collection.impl.vector.ArrayType.obj; - -/** - * NodeModifier. - *

- * References: - *

- * This class has been derived from 'vavr' BitMappedTrie.java. - *

- *
Vector.java. Copyright 2023 (c) vavr. MIT License.
- *
github.com
- *
- */ -@FunctionalInterface -interface NodeModifier { - Object apply(Object array, int index); - - NodeModifier COPY_NODE = (o, i) -> obj().copy(o, i + 1); - NodeModifier IDENTITY = (o, i) -> o; -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/mapped/MappedReadOnlyList.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/mapped/MappedReadOnlyList.java index df16117be..fc38853cb 100755 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/mapped/MappedReadOnlyList.java +++ b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/mapped/MappedReadOnlyList.java @@ -5,10 +5,10 @@ package org.jhotdraw8.collection.mapped; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.facade.ReadOnlySequencedCollectionFacade; -import org.jhotdraw8.collection.readonly.AbstractReadOnlyList; -import org.jhotdraw8.collection.readonly.ReadOnlyList; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedCollection; +import org.jhotdraw8.icollection.facade.ReadOnlySequencedCollectionFacade; +import org.jhotdraw8.icollection.readonly.AbstractReadOnlyList; +import org.jhotdraw8.icollection.readonly.ReadOnlyList; +import org.jhotdraw8.icollection.readonly.ReadOnlySequencedCollection; import java.util.Iterator; import java.util.NoSuchElementException; diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/ByteArrayList.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/ByteArrayList.java index 0d60358be..67c37e6df 100755 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/ByteArrayList.java +++ b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/ByteArrayList.java @@ -6,11 +6,18 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.facade.ListFacade; -import org.jhotdraw8.collection.sequenced.SequencedCollection; import org.jhotdraw8.collection.util.ListHelper; - -import java.util.*; +import org.jhotdraw8.icollection.facade.ListFacade; + +import java.util.AbstractList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Spliterator; import java.util.function.IntPredicate; import java.util.stream.IntStream; @@ -507,7 +514,7 @@ public void sort(@Nullable Comparator c) { } @Override - public @NonNull SequencedCollection _reversed() { + public @NonNull List reversed() { return new ListFacade<>( this::size, i -> get(size() - i) diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/ByteSequencedCollection.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/ByteSequencedCollection.java index cad5fb803..38595ccb0 100644 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/ByteSequencedCollection.java +++ b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/ByteSequencedCollection.java @@ -6,7 +6,8 @@ package org.jhotdraw8.collection.primitive; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.sequenced.SequencedCollection; + +import java.util.SequencedCollection; /** * Interface for collection of {@code int}-values with a well-defined linear diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/DoubleArrayList.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/DoubleArrayList.java index e0b985c63..2a2bddb9a 100755 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/DoubleArrayList.java +++ b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/DoubleArrayList.java @@ -6,11 +6,20 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.facade.ListFacade; -import org.jhotdraw8.collection.sequenced.SequencedCollection; import org.jhotdraw8.collection.util.ListHelper; - -import java.util.*; +import org.jhotdraw8.icollection.facade.ListFacade; + +import java.util.AbstractList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.PrimitiveIterator; +import java.util.Spliterator; +import java.util.Spliterators; import java.util.function.DoublePredicate; import java.util.stream.DoubleStream; @@ -496,7 +505,7 @@ public void sort(@Nullable Comparator c) { } @Override - public @NonNull SequencedCollection _reversed() { + public @NonNull List reversed() { return new ListFacade<>( this::size, i -> get(size() - i) diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/DoubleSequencedCollection.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/DoubleSequencedCollection.java index 40183c6f1..e993eeea9 100644 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/DoubleSequencedCollection.java +++ b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/DoubleSequencedCollection.java @@ -6,7 +6,8 @@ package org.jhotdraw8.collection.primitive; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.sequenced.SequencedCollection; + +import java.util.SequencedCollection; /** * Interface for collection of {@code int}-values with a well-defined linear diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntArrayDeque.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntArrayDeque.java index 2c461391d..f7408561a 100755 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntArrayDeque.java +++ b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntArrayDeque.java @@ -5,9 +5,13 @@ package org.jhotdraw8.collection.primitive; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.sequenced.SequencedCollection; -import java.util.*; +import java.util.AbstractCollection; +import java.util.ConcurrentModificationException; +import java.util.Deque; +import java.util.Iterator; +import java.util.NoSuchElementException; +import java.util.Objects; /** * A {@code int}-valued deque backed by a primitive array. @@ -279,7 +283,7 @@ public boolean isEmpty() { } @Override - public @NonNull SequencedCollection _reversed() { + public @NonNull Deque reversed() { return null; } diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntArrayList.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntArrayList.java index d9276b669..94306e18b 100755 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntArrayList.java +++ b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntArrayList.java @@ -6,11 +6,20 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.facade.ListFacade; -import org.jhotdraw8.collection.sequenced.SequencedCollection; import org.jhotdraw8.collection.util.ListHelper; - -import java.util.*; +import org.jhotdraw8.icollection.facade.ListFacade; + +import java.util.AbstractList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.PrimitiveIterator; +import java.util.Spliterator; +import java.util.Spliterators; import java.util.function.IntPredicate; import java.util.stream.IntStream; @@ -495,7 +504,7 @@ public void sort(@Nullable Comparator c) { } @Override - public @NonNull SequencedCollection _reversed() { + public @NonNull List reversed() { return new ListFacade<>( this::size, i -> get(size() - i) diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntRangeSet.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntRangeSet.java index f886bb16a..4b6cdbb36 100644 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntRangeSet.java +++ b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntRangeSet.java @@ -6,7 +6,7 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.readonly.AbstractReadOnlySet; +import org.jhotdraw8.icollection.readonly.AbstractReadOnlySet; import java.util.Iterator; import java.util.Objects; diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntSequencedCollection.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntSequencedCollection.java index 53e9d47fd..6fa137185 100644 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntSequencedCollection.java +++ b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntSequencedCollection.java @@ -6,7 +6,8 @@ package org.jhotdraw8.collection.primitive; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.sequenced.SequencedCollection; + +import java.util.SequencedCollection; /** * Interface for collection of {@code int}-values with a well-defined linear diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/AbstractReadOnlyCollection.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/AbstractReadOnlyCollection.java deleted file mode 100755 index 9e22d94e3..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/AbstractReadOnlyCollection.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * @(#)AbstractReadOnlyCollection.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.readonly; - -import org.jhotdraw8.annotation.NonNull; - -import java.util.Objects; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -/** - * Abstract base class for {@link ReadOnlyCollection}s. - * - * @param the element type - */ -public abstract class AbstractReadOnlyCollection implements ReadOnlyCollection { - /** - * Sole constructor. (For invocation by subclass constructors, typically implicit.). - */ - public AbstractReadOnlyCollection() { - } - - /** - * Returns a string representation of this collection. The string - * representation consists of a list of the collection's elements in the - * order they are returned by its iterator, enclosed in square brackets - * ({@code "[]"}). Adjacent elements are separated by the characters - * {@code ", "} (comma and space). Elements are converted to strings as - * by {@link String#valueOf(Object)}. - * - * @return a string representation of this collection - */ - public final @NonNull String toString() { - return ReadOnlyCollection.iterableToString(this); - } - - @Override - public boolean contains(Object o) { - for (E e : this) { - if (Objects.equals(o, e)) { - return true; - } - } - return false; - } - - @Override - public Stream stream() { - return StreamSupport.stream(spliterator(), false); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/AbstractReadOnlyList.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/AbstractReadOnlyList.java deleted file mode 100755 index c17ba7a53..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/AbstractReadOnlyList.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * @(#)AbstractReadOnlyList.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.readonly; - -/** - * Abstract base class for {@link ReadOnlyList}s. - * - * @param the element type - */ -public abstract class AbstractReadOnlyList extends AbstractReadOnlyCollection implements ReadOnlyList { - /** - * Constructs a new instance. - */ - public AbstractReadOnlyList() { - } - - - @Override - public boolean equals(Object o) { - return ReadOnlyList.listEquals(this, o); - } - - @Override - public int hashCode() { - return ReadOnlyList.iteratorToHashCode(iterator()); - } - -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/AbstractReadOnlyMap.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/AbstractReadOnlyMap.java deleted file mode 100755 index 65a9848c2..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/AbstractReadOnlyMap.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * @(#)AbstractReadOnlyMap.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.readonly; - -import org.jhotdraw8.annotation.NonNull; - -/** - * Abstract base class for {@link ReadOnlyMap}s. - * - * @param the key type - * @param the value type - */ -public abstract class AbstractReadOnlyMap implements ReadOnlyMap { - /** - * Constructs a new instance. - */ - public AbstractReadOnlyMap() { - } - - public boolean equals(Object o) { - return ReadOnlyMap.mapEquals(this, o); - } - - @Override - public int hashCode() { - return ReadOnlyMap.iteratorToHashCode(iterator()); - } - - @Override - public final @NonNull String toString() { - return ReadOnlyMap.mapToString(this); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/AbstractReadOnlySet.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/AbstractReadOnlySet.java deleted file mode 100755 index b61e63973..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/AbstractReadOnlySet.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * @(#)AbstractReadOnlySet.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.readonly; - -/** - * Abstract base class for {@link ReadOnlySet}s. - * - * @param the element type - */ -public abstract class AbstractReadOnlySet extends AbstractReadOnlyCollection implements ReadOnlySet { - /** - * Constructs a new instance. - */ - public AbstractReadOnlySet() { - } - - @Override - public boolean equals(Object o) { - return ReadOnlySet.setEquals(this, o); - } - - @Override - public int hashCode() { - return ReadOnlySet.iteratorToHashCode(this.iterator()); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlyCollection.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlyCollection.java deleted file mode 100755 index a2a8caf64..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlyCollection.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * @(#)ReadOnlyCollection.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.readonly; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.facade.CollectionFacade; - -import java.util.Arrays; -import java.util.Collection; -import java.util.ConcurrentModificationException; -import java.util.Iterator; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -/** - * Read-only interface for a collection. The state - * of the collection may change. - *

- * This interface does not guarantee 'read-only', it actually guarantees - * 'readable'. We use the prefix 'ReadOnly' because this is the naming - * convention in JavaFX for interfaces that provide read methods but no write methods. - * - * @param the element type - */ -public interface ReadOnlyCollection extends Iterable { - - /** - * Returns the maximal size of this collection. - *

- * Attempting to add more elements to this collection will result - * in a {@link SizeLimitExceededException}. - *

- * The default implementation provided by this interface - * returns {@link Integer#MAX_VALUE} {@code - 16}. - * This is the largest supported array size on a JVM when - * pointers are not compressed. - * - * @return the maximal size - */ - default long maxSize() { - return Integer.MAX_VALUE - 16; - } - - - /** - * Returns the size of the collection. - *

- * If this collection contains more than {@link Integer#MAX_VALUE} - * elements, returns {@link Integer#MAX_VALUE}. - * - * @return the size - */ - int size(); - - /** - * Returns the size of the collection as a long value. - *

- * The default implementation provided by this interface - * returns {@link #size()}. - * - * @return the size - */ - default long sizeAsLong() { - return size(); - } - - /** - * Returns true if the collection is empty. - * - * @return true if empty - */ - default boolean isEmpty() { - return size() == 0; - } - - default Object @NonNull [] toArray() { - return toArray(new Object[size()]); - } - - /** - * Converts the collection to an array. - * - * @param the element type - * @param a a template array - * @return an array - */ - default @NonNull T @NonNull [] toArray(@NonNull T @NonNull [] a) { - // Estimate size of array; be prepared to see more or fewer elements - int size = size(); - @SuppressWarnings("unchecked") - T[] r = a.length >= size ? a : (T[]) Arrays.copyOf(a, size, a.getClass()); - Iterator it = iterator(); - - for (int i = 0; i < r.length; i++) { - if (!it.hasNext()) { // fewer elements than expected - throw new ConcurrentModificationException("fewer elements than expected. expected=" + size); - } - @SuppressWarnings("unchecked") - T t = (T) it.next(); - r[i] = t; - } - if (it.hasNext()) { - throw new ConcurrentModificationException("more elements than expected. expected=" + size); - } - return r; - } - - /** - * Returns a stream. - * - * @return a stream - */ - default Stream stream() { - return StreamSupport.stream(spliterator(), false); - } - - /** - * Returns {@code true} if this collection contains the specified object. - * - * @param o an object - * @return {@code true} if this collection contains the specified - * object - */ - boolean contains(Object o); - - /** - * Returns an iterator over the elements in this collection. - * - * @return an iterator - */ - @Override - @NonNull - Iterator iterator(); - - /** - * Returns true if this collection contains all elements of that collection. - * - * @param c another collection - * @return true if this collection contains all of c - */ - default boolean containsAll(@NonNull Iterable c) { - for (Object e : c) { - if (!contains(e)) { - return false; - } - } - return true; - } - - /** - * Wraps this collection in the Collection interface - without copying. - * - * @return the wrapped collection - */ - default @NonNull Collection asCollection() { - return new CollectionFacade<>(this); - } - - /** - * Returns a string representation of the provided iterable. The string - * representation consists of a list of the iterable's elements in the - * order they are returned, enclosed in square brackets - * ({@code "[]"}). Adjacent elements are separated by the characters - * {@code ", "} (comma and space). Elements are converted to strings as - * by {@link String#valueOf(Object)}. - * - * @param c an iterable - * @param the element type - * @return a string representation of the iterable - */ - static @NonNull String iterableToString(final @NonNull Iterable c) { - Iterator it = c.iterator(); - if (!it.hasNext()) { - return "[]"; - } - - StringBuilder sb = new StringBuilder(); - sb.append('['); - for (; ; ) { - E e = it.next(); - sb.append(e == c ? "(this Collection)" : e); - if (!it.hasNext()) { - return sb.append(']').toString(); - } - sb.append(',').append(' '); - } - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlyList.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlyList.java deleted file mode 100755 index 807cada31..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlyList.java +++ /dev/null @@ -1,277 +0,0 @@ -/* - * @(#)ReadOnlyList.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.readonly; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.facade.ListFacade; -import org.jhotdraw8.collection.facade.ReadOnlyListFacade; -import org.jhotdraw8.collection.spliterator.ReadOnlyListSpliterator; - -import java.util.*; - -/** - * Read-only interface for a list. The state of the - * list may change. - *

- * Note: To compare a ReadOnlyList to a {@link List}, you must either - * wrap the ReadOnlyList into a List using {@link ListFacade}, - * or wrap the List into a ReadOnlyList using {@link ReadOnlyListFacade}. - *

- * This interface does not guarantee 'read-only', it actually guarantees - * 'readable'. We use the prefix 'ReadOnly' because this is the naming - * convention in JavaFX for interfaces that provide read methods but no write methods. - * - * @param the element type - */ -public interface ReadOnlyList extends ReadOnlySequencedCollection { - - /** - * Returns the element at the specified position in this list. - * - * @param index the index of the element - * @return the element - * @throws IndexOutOfBoundsException if the index is out of range - * ({@code index < 0 || index >= size()}) - */ - E get(int index); - - /** - * Returns the element at the specified position in this list, counted - * from the last element of the list. - * - * @param index the index of the element, counted from the last - * element. - * @return the element - * @throws IndexOutOfBoundsException if the index is out of range - * ({@code index < 0 || index >= size()}) - */ - default E getLast(int index) { - return get(size() - index - 1); - } - - /** - * Gets the first element of the list. - * - * @return the first element - * @throws java.util.NoSuchElementException if the list is empty - */ - @Override - default E getFirst() { - if (isEmpty()) { - throw new NoSuchElementException(); - } - return get(0); - } - - /** - * Gets the last element of the list. - * - * @return the last element - * @throws java.util.NoSuchElementException if the list is empty - */ - @Override - default E getLast() { - int index = size() - 1; - if (index < 0) { - throw new NoSuchElementException(); - } - return get(index); - } - - /** - * Peeks the first element of the list. - * - * @return the first element or null if the list is empty - */ - default @Nullable E peekFirst() { - return isEmpty() ? null : get(0); - } - - /** - * Peeks the last element of the list. - * - * @return the last element or null if the list is empty - */ - default @Nullable E peekLast() { - int index = size() - 1; - return index < 0 ? null : get(index); - } - - /** - * Returns an iterator over elements of type {@code E}. - * - * @return an iterator. - */ - @Override - default @NonNull Iterator iterator() { - return new ReadOnlyListSpliterator<>(this); - } - - /** - * Returns a spliterator over elements of type {@code E}. - * - * @return an iterator. - */ - @Override - default @NonNull Spliterator spliterator() { - return new ReadOnlyListSpliterator<>(this); - } - - /** - * Returns a list iterator over elements of type {@code E}. - * - * @return a list iterator. - */ - default @NonNull ListIterator listIterator() { - return new ReadOnlyListSpliterator<>(this); - } - - /** - * Returns a list iterator over elements of type {@code E} starting - * at the specified index. - * - * @param index the start index - * @return a list iterator. - */ - default @NonNull ListIterator listIterator(int index) { - return new ReadOnlyListSpliterator<>(this, index, size()); - } - - /** - * Copies this list into an ArrayList. - * - * @return a new ArrayList. - */ - default @NonNull ArrayList toArrayList() { - return new ArrayList<>(this.asList()); - } - - /** - * Wraps this list in the List interface - without copying. - * - * @return the wrapped list - */ - default @NonNull List asList() { - return new ListFacade<>(this); - } - - /** - * Returns a view of the portion of this list between the specified - * * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive. - * - * @param fromIndex the from index - * @param toIndex the to index (exclusive) - * @return the sub list - */ - @NonNull - ReadOnlyList readOnlySubList(int fromIndex, int toIndex); - - /** - * Returns the index of the first occurrence of the specified element - * in this list, or -1 if this list does not contain the element. - * - * @param o an element - * @return the index of the element or -1 - */ - default int indexOf(Object o) { - for (int i = 0, n = size(); i < n; i++) { - if (Objects.equals(get(i), o)) { - return i; - } - } - return -1; - } - - /** - * Returns the index of the last occurrence of the specified element - * in this list, or -1 if this list does not contain the element. - * - * @param o an element - * @return the index of the element or -1 - */ - default int lastIndexOf(Object o) { - for (int i = size() - 1; i >= 0; i--) { - if (Objects.equals(get(i), o)) { - return i; - } - } - return -1; - } - - /** - * Compares the given list with the given object for equality. - *

- * Returns {@code true} if the given object is also a read-only list and the - * two lists contain the same elements in the same sequence. - * - * @param list a list - * @param o an object - * @param the element type of the list - * @return {@code true} if the object is equal to this list - */ - static boolean listEquals(@NonNull ReadOnlyList list, @Nullable Object o) { - if (o == list) { - return true; - } - if (!(o instanceof ReadOnlyList)) { - return false; - } - - @SuppressWarnings("unchecked") - ReadOnlyCollection that = (ReadOnlyCollection) o; - if (that.size() != list.size()) { - return false; - } - for (Iterator i = that.iterator(), j = list.iterator(); j.hasNext(); ) { - if (!Objects.equals(i.next(), j.next())) { - return false; - } - } - return true; - } - - /** - * Returns the hash code of the provided iterable, assuming that - * the iterator is from a list. - * - * @param iterator an iterator over a list - * @param the element type - * @return the ordered sum of the hash codes of the elements in the list - * @see List#hashCode() - */ - static int iteratorToHashCode(@NonNull Iterator iterator) { - int h = 1; - while (iterator.hasNext()) { - E e = iterator.next(); - h = 31 * h + (e == null ? 0 : e.hashCode()); - } - return h; - } - - /** - * Compares the specified object with this list for equality. - *

- * Returns {@code true} if the given object is also a read-only list and the - * two lists contain the same elements in the same sequence. - *

- * Implementations of this method should use {@link ReadOnlyList#listEquals}. - * - * @param o an object - * @return {@code true} if the object is equal to this list - */ - boolean equals(@Nullable Object o); - - /** - * Returns the hash code value for this list. The hash code - * is the result of the calculation described in {@link List#hashCode()}. - *

- * Implementations of this method should use {@link ReadOnlyList#iteratorToHashCode}. - * - * @return the hash code value for this set - */ - int hashCode(); - -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlyMap.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlyMap.java deleted file mode 100755 index 1564eead5..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlyMap.java +++ /dev/null @@ -1,314 +0,0 @@ -/* - * @(#)ReadOnlyMap.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.readonly; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.facade.MapFacade; -import org.jhotdraw8.collection.facade.ReadOnlyCollectionFacade; -import org.jhotdraw8.collection.facade.ReadOnlySetFacade; -import org.jhotdraw8.collection.mapped.MappedIterator; - -import java.util.*; - -/** - * Read-only interface for a map. The state of the - * map may change. - * - * @param the key type - * @param the value type - */ -public interface ReadOnlyMap extends Iterable> { - /** - * Returns {@code true} if this map contains no entries. - * - * @return {@code true} if empty - */ - boolean isEmpty(); - - /** - * Returns the maximal size of this collection. - *

- * Attempting to add more elements to this collection will result - * in a {@link SizeLimitExceededException}. - *

- * The default implementation provided by this interface - * returns {@link Integer#MAX_VALUE} {@code - 4}. - * - * @return the maximal size - */ - default long maxSize() { - return Integer.MAX_VALUE - 4; - } - - /** - * Returns the number of entries contained in this map.. - * - * @return the number of entries - */ - int size(); - - /** - * Returns the size of the collection as a long value. - *

- * The default implementation provided by this interface - * returns {@link #size()}. - * - * @return the size - */ - default long sizeAsLong() { - return size(); - } - - /** - * Returns the value to which the key is mapped, or {@code null} if this map - * contains no entry for the key. - * - * @param key a key - * @return the mapped value or {@code null} - */ - @Nullable V get(Object key); - - /** - * Returns the value to which the key is mapped, or the specified default - * value if this map contains no entry for the key. - * - * @param key a key - * @param defaultValue a default value - * @return the mapped value or the specified default value - */ - default @Nullable V getOrDefault(@NonNull Object key, @Nullable V defaultValue) { - V v; - return (((v = get(key)) != null) || containsKey(key)) - ? v - : defaultValue; - } - - /** - * Returns {@code true} if this map contains a entry for the specified - * key. - * - * @param key a key - * @return {@code true} if this map contains a entry for the specified - * key - */ - boolean containsKey(@Nullable Object key); - - /** - * Returns {@code true} if this map contains one or more keys to the - * specified value. - * - * @param value a value - * @return {@code true} if this map maps one or more keys to the - * specified value - */ - default boolean containsValue(@Nullable Object value) { - for (Map.Entry entry : this) { - if (Objects.equals(value, entry.getValue())) { - return true; - } - } - return false; - } - - /** - * Returns true if this map contains the specified entry. - * - * @param o an entry (should be a {@link Map.Entry}). - * @return true if this map contains the entry - */ - default boolean containsEntry(Object o) { - if (o instanceof Map.Entry) { - @SuppressWarnings("unchecked") Map.Entry entry = (Map.Entry) o; - return containsKey(entry.getKey()) - && Objects.equals(entry.getValue(), get(entry.getKey())); - } - return false; - } - - /** - * Returns a {@link ReadOnlySet} view to the entries contained - * in this map. - * - * @return a read-only view - */ - default @NonNull ReadOnlySet> readOnlyEntrySet() { - return new ReadOnlySetFacade<>( - this::iterator, - this::size, - this::containsEntry - ); - } - - /** - * Returns a {@link ReadOnlySet} view to the keys contained - * in this map. - * - * @return a read-only view - */ - default @NonNull ReadOnlySet readOnlyKeySet() { - return new ReadOnlySetFacade<>( - () -> new MappedIterator<>(ReadOnlyMap.this.iterator(), Map.Entry::getKey), - this::size, - this::containsKey - ); - } - - /** - * Returns a {@link ReadOnlyCollection} view to the values contained - * in this map. - * - * @return a read-only view - */ - default @NonNull ReadOnlyCollection readOnlyValues() { - return new ReadOnlyCollectionFacade<>( - () -> new MappedIterator<>(ReadOnlyMap.this.iterator(), Map.Entry::getValue), - this::size, - this::containsValue - ); - } - - /** - * Wraps this map in the {@link Map} interface - without copying. - * - * @return the wrapped map - */ - default @NonNull Map asMap() { - return new MapFacade<>(this); - } - - /** - * Returns a string representation of the specified map. - *

- * The string representation is consistent with the one produced - * by {@link AbstractMap#toString()}. - * - * @param map a map - * @param the key type - * @param the value type - * @return a string representation - */ - static @NonNull String mapToString(final @NonNull ReadOnlyMap map) { - Iterator> i = map.iterator(); - if (!i.hasNext()) { - return "{}"; - } - - StringBuilder sb = new StringBuilder(); - sb.append('{'); - for (; ; ) { - Map.Entry e = i.next(); - K key = e.getKey(); - V value = e.getValue(); - sb.append(key == map ? "(this Map)" : key); - sb.append('='); - sb.append(value == map ? "(this Map)" : value); - if (!i.hasNext()) { - return sb.append('}').toString(); - } - sb.append(',').append(' '); - } - } - - /** - * Compares a read-only map with an object for equality. Returns - * {@code true} if the given object is also a read-only map and the two maps - * represent the same entries. - * - * @param map a map - * @param o an object - * @param the key type - * @param the value type - * @return {@code true} if the object is equal to the map - */ - static boolean mapEquals(@NonNull ReadOnlyMap map, Object o) { - if (o == map) { - return true; - } - - if (!(o instanceof ReadOnlyMap)) { - return false; - } - @SuppressWarnings("unchecked") - ReadOnlyMap that = (ReadOnlyMap) o; - if (that.size() != map.size()) { - return false; - } - - try { - for (Map.Entry e : map) { - K key = e.getKey(); - V value = e.getValue(); - if (value == null) { - if (!(that.get(key) == null && that.containsKey(key))) { - return false; - } - } else { - if (!value.equals(that.get(key))) { - return false; - } - } - } - } catch (@NonNull ClassCastException | NullPointerException unused) { - return false; - } - - return true; - } - - /** - * Returns the hash code of the provided iterable. The hash code - * is the sum of the hash code of the entries. - * - * @param entries an iterable that is an entry set - * @param the key type - * @param the value type - * @return the sum of the hash codes of the elements in the set - * @see Map#hashCode() - */ - static int iteratorToHashCode(@NonNull Iterator> entries) { - return ReadOnlySet.iteratorToHashCode(entries); - } - - /** - * Compares the specified object with this map for equality. - *

- * Returns {@code true} if the given object is also a read-only map and the - * two maps represent the same entries, ignorig the sequence of the - * map entries. - * - * @param o an object - * @return {@code true} if the object is equal to this map - */ - boolean equals(Object o); - - /** - * Returns the hash code value for this map. The hash code - * is the sum of the hash code of its entries. - * - * @return the hash code value for this map - * @see Map#hashCode() - */ - int hashCode(); - - /** - * Returns an iterator over the entries contained in this map. - * - * @return an iterator - */ - @Override - @NonNull Iterator> iterator(); - - /** - * Returns a spliterator over the entries contained in this map. - * - * @return a spliterator - */ - @NonNull - @Override - default Spliterator> spliterator() { - return Iterable.super.spliterator(); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlySequencedCollection.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlySequencedCollection.java deleted file mode 100644 index be16ebf0b..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlySequencedCollection.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * @(#)ReadOnlySequencedCollection.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.readonly; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.facade.SequencedCollectionFacade; -import org.jhotdraw8.collection.sequenced.SequencedCollection; - -/** - * Read-only interface for a collection with a well-defined iteration order. - * - * @param the element type - */ -public interface ReadOnlySequencedCollection extends ReadOnlyCollection { - /** - * Gets the first element. - * - * @return an element - * @throws java.util.NoSuchElementException if the collection is empty - */ - default E getFirst() { - return iterator().next(); - } - - /** - * Gets the last element. - * - * @return an element - * @throws java.util.NoSuchElementException if the collection is empty - */ - default E getLast() { - return readOnlyReversed().iterator().next(); - } - - - /** - * Returns a reversed-order view of this collection. - * Changes to the underlying collection are visible in the reversed view. - * - * @return a reversed-order view of this collection - */ - @NonNull ReadOnlySequencedCollection readOnlyReversed(); - - @Override - default @NonNull SequencedCollection asCollection() { - return new SequencedCollectionFacade(this); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlySequencedMap.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlySequencedMap.java deleted file mode 100644 index 5895007af..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlySequencedMap.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * @(#)ReadOnlySequencedMap.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.readonly; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.facade.ReadOnlySequencedSetFacade; -import org.jhotdraw8.collection.facade.SequencedMapFacade; -import org.jhotdraw8.collection.mapped.MappedIterator; -import org.jhotdraw8.collection.sequenced.SequencedMap; - -import java.util.Map; -import java.util.NoSuchElementException; - -/** - * Read-only interface for a map with a well-defined iteration order. - * The state of the map may change. - *

- * References: - *

- *
JEP draft: Sequenced Collections
- *
java.ne
- *
- * - * @param the key type - * @param the value type - */ -public interface ReadOnlySequencedMap extends ReadOnlyMap { - /** - * Returns a reversed-order view of this map. - *

- * Changes to the underlying map are visible in the reversed view. - * - * @return a reversed-order view of this map - */ - @NonNull ReadOnlySequencedMap readOnlyReversed(); - - /** - * Gets the first entry in this map or {@code null} if this map is empty. - * - * @return the first entry or {@code null} - * @throws java.util.NoSuchElementException if the map is empty - */ - default Map.@Nullable Entry firstEntry() { - return isEmpty() ? null : readOnlyEntrySet().iterator().next(); - } - - /** - * Gets the last entry in this map or {@code null} if this map is empty. - * - * @return the last entry or {@code null} - * @throws java.util.NoSuchElementException if the map is empty - */ - default Map.@Nullable Entry lastEntry() { - return isEmpty() ? null : readOnlyReversed().readOnlyEntrySet().iterator().next(); - } - - @Override - @NonNull - default ReadOnlySet> readOnlyEntrySet() { - return readOnlySequencedEntrySet(); - } - - @Override - @NonNull - default ReadOnlySet readOnlyKeySet() { - return readOnlySequencedKeySet(); - } - - @Override - @NonNull - default ReadOnlyCollection readOnlyValues() { - return readOnlySequencedValues(); - } - - /** - * Returns a {@link ReadOnlySequencedSet} view of the entries contained in this map. - * - * @return a {@link ReadOnlySequencedSet} view of the entries - */ - default @NonNull ReadOnlySequencedSet> readOnlySequencedEntrySet() { - return new ReadOnlySequencedSetFacade<>( - this::iterator, - () -> readOnlyReversed().readOnlyEntrySet().iterator(), - this::size, - this::containsEntry, - this::firstEntry, - this::lastEntry - ); - } - - /** - * Returns a {@link ReadOnlySequencedSet} view of the keys contained in this map. - * - * @return a {@link ReadOnlySequencedSet} view of the keys - */ - default @NonNull ReadOnlySequencedSet readOnlySequencedKeySet() { - return new ReadOnlySequencedSetFacade<>( - () -> new MappedIterator<>(iterator(), Map.Entry::getKey), - () -> new MappedIterator<>(readOnlyReversed().readOnlyEntrySet().iterator(), Map.Entry::getKey), - this::size, - this::containsKey, - () -> { - Map.Entry e = firstEntry(); - if (e == null) throw new NoSuchElementException(); - return e.getKey(); - }, - () -> { - Map.Entry e = lastEntry(); - if (e == null) throw new NoSuchElementException(); - return e.getKey(); - } - ); - } - - /** - * Returns a {@link ReadOnlySequencedCollection} view of the values contained in - * this map. - * - * @return a {@link ReadOnlySequencedCollection} view of the values - */ - default @NonNull ReadOnlySequencedCollection readOnlySequencedValues() { - return new ReadOnlySequencedSetFacade<>( - () -> new MappedIterator<>(iterator(), Map.Entry::getValue), - () -> new MappedIterator<>(readOnlyReversed().readOnlyEntrySet().iterator(), Map.Entry::getValue), - this::size, - this::containsValue, - () -> { - Map.Entry e = firstEntry(); - if (e == null) throw new NoSuchElementException(); - return e.getValue(); - }, - () -> { - Map.Entry e = lastEntry(); - if (e == null) throw new NoSuchElementException(); - return e.getValue(); - } - ); - } - - @Override - @NonNull - default SequencedMap asMap() { - return new SequencedMapFacade<>(this); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlySequencedSet.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlySequencedSet.java deleted file mode 100644 index 4f73866a8..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlySequencedSet.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * @(#)ReadOnlySequencedSet.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.readonly; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.facade.SequencedSetFacade; -import org.jhotdraw8.collection.sequenced.SequencedSet; - -/** - * Read-only interface for a set with a well-defined iteration order. - * The state of the set may change. - *

- * References: - *

- *
JEP draft: Sequenced Collections
- *
java.ne
- *
- * - * @param the element type - */ -public interface ReadOnlySequencedSet extends ReadOnlySet, ReadOnlySequencedCollection { - /** - * Returns a reversed-order view of this set. - * Changes to the underlying set are visible in the reversed view. - * - * @return a reversed-order view of this set - */ - @NonNull ReadOnlySequencedSet readOnlyReversed(); - - @Override - default @NonNull SequencedSet asSet() { - return new SequencedSetFacade<>(this); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlySet.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlySet.java deleted file mode 100755 index e4cd08f90..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/ReadOnlySet.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * @(#)ReadOnlySet.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.readonly; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.facade.ReadOnlySetFacade; -import org.jhotdraw8.collection.facade.SetFacade; - -import java.util.Iterator; -import java.util.Set; - -/** - * Read-only interface for a set. The state of the set may change. - *

- * Note: To compare a ReadOnlySet to a {@link Set}, you must either - * wrap the ReadOnlySet into a Set using {@link SetFacade}, - * or wrap the Set into a ReadOnlySet using {@link ReadOnlySetFacade}. - *

- * This interface does not guarantee 'read-only', it actually guarantees - * 'readable'. We use the prefix 'ReadOnly' because this is the naming - * convention in JavaFX for interfaces that provide read methods but no write methods. - * - * @param the element type - */ -public interface ReadOnlySet extends ReadOnlyCollection { - /** - * Returns the sum of the hash codes of all elements in the provided - * iterator. - * - * @param iterator an iterator - * @param the element type - * @return the sum of the hash codes of the elements - * @see Set#hashCode() - */ - static int iteratorToHashCode(@NonNull Iterator iterator) { - int h = 0; - while (iterator.hasNext()) { - E e = iterator.next(); - if (e != null) { - h += e.hashCode(); - } - } - return h; - } - - /** - * Compares a read-only set with an object for equality. Returns - * {@code true} if the given object is also a read-only set and the two sets - * contain the same elements. - * - * @param set a set - * @param o an object - * @param the element type - * @return {@code true} if the object is equal to the set - */ - static boolean setEquals(@NonNull ReadOnlySet set, @Nullable Object o) { - if (o == set) { - return true; - } - if (o instanceof ReadOnlySet) { - @SuppressWarnings("unchecked") - ReadOnlySet that = (ReadOnlySet) o; - return set.size() == that.size() && set.containsAll(that); - } - return false; - } - - - /** - * Wraps this set in the Set interface - without copying. - * - * @return the wrapped set - */ - default @NonNull Set asSet() { - return new SetFacade<>(this); - } - - /** - * Compares the specified object with this set for equality. - *

- * Returns {@code true} if the given object is also a read-only set and the - * two sets contain the same elements, ignoring the sequence of the elements. - *

- * Implementations of this method should use {@link ReadOnlySet#setEquals}. - * - * @param o an object - * @return {@code true} if the object is equal to this map - */ - boolean equals(@Nullable Object o); - - /** - * Returns the hash code value for this set. The hash code - * is the sum of the hash code of its elements. - *

- * Implementations of this method should use {@link ReadOnlySet#iteratorToHashCode}. - * - * @return the hash code value for this set - * @see Set#hashCode() - */ - int hashCode(); -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/package-info.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/package-info.java deleted file mode 100755 index 033a5f9f2..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/package-info.java +++ /dev/null @@ -1,9 +0,0 @@ -/* - * @(#)package-info.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -/** - * Defines interfaces for read-only collections and provides abstract base classes. - */ -package org.jhotdraw8.collection.readonly; diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/AbstractSequencedMap.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/AbstractSequencedMap.java deleted file mode 100644 index 2f067eaf9..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/AbstractSequencedMap.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * @(#)AbstractSequencedMap.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.sequenced; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.facade.SequencedCollectionFacade; -import org.jhotdraw8.collection.facade.SequencedSetFacade; -import org.jhotdraw8.collection.mapped.MappedIterator; -import org.jhotdraw8.collection.mapped.MappedSpliterator; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedMap; - -import java.util.*; - -/** - * Abstract base class for {@link SequencedMap}s. - * - * @param the key type - * @param the value type - */ -public abstract class AbstractSequencedMap extends AbstractMap implements SequencedMap, ReadOnlySequencedMap { - /** - * Constructs a new instance. - */ - public AbstractSequencedMap() { - } - - boolean removeKey(final @Nullable Object o) { - if (containsKey(o)) { - remove(o); - return true; - } - return false; - } - - boolean removeValue(final @Nullable Object o) { - for (Entry entry : _sequencedEntrySet()) { - if (Objects.equals(entry.getValue(), o)) { - remove(entry.getKey()); - return true; - } - } - return false; - } - - @Override - public @Nullable Entry firstEntry() { - return SequencedMap.super.firstEntry(); - } - - @Override - public @Nullable Entry lastEntry() { - return SequencedMap.super.lastEntry(); - } - - @Override - public @NonNull SequencedSet _sequencedKeySet() { - return createKeySet(this); - } - - @Override - public @NonNull SequencedSet keySet() { - return createKeySet(this); - } - - @Override - public @NonNull Set> entrySet() { - return _sequencedEntrySet(); - } - - - /** - * Creates a set that contains the keys of the provided map. - * - * @param m a map - * @param the key type of the map - * @param the value type of the map - * @return a set of the keys - */ - @SuppressWarnings({"SuspiciousMethodCalls"}) - public static @NonNull SequencedSet createKeySet(@NonNull SequencedMap m) { - return new SequencedSetFacade<>( - () -> new MappedIterator<>(m._sequencedEntrySet().iterator(), Entry::getKey), - () -> new MappedSpliterator<>(m._sequencedEntrySet().spliterator(), Entry::getKey, Spliterator.DISTINCT | Spliterator.SIZED), - () -> new MappedIterator<>(m._reversed()._sequencedEntrySet().iterator(), Entry::getKey), - () -> new MappedSpliterator<>(m._reversed()._sequencedEntrySet().spliterator(), Entry::getKey, Spliterator.DISTINCT | Spliterator.SIZED), - m::size, - m::containsKey, - m::clear, - o -> { - if (m.containsKey(o)) { - m.remove(o); - return true; - } - return false; - }, - () -> { - Entry e = m.firstEntry(); - if (e == null) throw new NoSuchElementException(); - return e.getKey(); - }, - () -> { - Entry e = m.lastEntry(); - if (e == null) throw new NoSuchElementException(); - return e.getKey(); - }, - null, null, null, null); - } - - @Override - public @NonNull SequencedCollection _sequencedValues() { - return createValues(this); - } - - @Override - public @NonNull SequencedCollection values() { - return createValues(this); - } - - /** - * Creates a collection that contains the values of the provided map. - * - * @param m a map - * @param the key type of the map - * @param the value type of the map - * @return a collection of the values - */ - public static @NonNull SequencedCollection createValues(@NonNull SequencedMap m) { - return new SequencedCollectionFacade<>( - () -> new MappedIterator<>(m._sequencedEntrySet().iterator(), Entry::getValue), - () -> new MappedIterator<>(m._reversed()._sequencedEntrySet().iterator(), Entry::getValue), - m::size, - m::containsValue, - m::clear, - (o) -> { - for (Entry entry : m._sequencedEntrySet()) { - if (Objects.equals(entry.getValue(), o)) { - m.remove(entry.getKey()); - return true; - } - } - return false; - }, - () -> { - Entry entry = m.firstEntry(); - if (entry == null) { - throw new NoSuchElementException(); - } - return entry.getValue(); - }, - () -> { - Entry entry = m.lastEntry(); - if (entry == null) { - throw new NoSuchElementException(); - } - return entry.getValue(); - }, - null, null - ); - } - - @Override - public V getOrDefault(@NonNull Object key, V defaultValue) { - return SequencedMap.super.getOrDefault(key, defaultValue); - } - - @Override - public @NonNull Iterator> iterator() { - return _sequencedEntrySet().iterator(); - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/AbstractSequencedSet.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/AbstractSequencedSet.java deleted file mode 100644 index f5dae1036..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/AbstractSequencedSet.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.jhotdraw8.collection.sequenced; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.facade.SequencedSetFacade; - -import java.util.AbstractSet; -import java.util.Iterator; -import java.util.Spliterator; - -/** - * Abstract base class for {@link SequencedSet}s. - * - * @param the element type - */ -public abstract class AbstractSequencedSet extends AbstractSet implements SequencedSet { - @Override - public @NonNull SequencedSet _reversed() { - return new SequencedSetFacade<>( - this::reverseIterator, - this::reverseSpliterator, - this::iterator, - this::spliterator, - this::size, - this::contains, - this::clear, - this::remove, - this::getLast, this::getFirst, - this::reverseAdd, this::add, - this::addLast, this::addFirst - ); - } - - /** - * Returns an iterator that iterates in the reverse - * sequence over the elements contained in this collection. - * - * @return an iterator that iterates in reverse - */ - protected abstract Iterator reverseIterator(); - - /** - * Returns a spliterator that iterates in the reverse - * sequence over the elements contained in this collection. - * - * @return a spliterator that iterates in reverse - */ - protected abstract Spliterator reverseSpliterator(); - - /** - * Adds an element to the set. If the element was not in the set, - * it is added at the front of this collection. - * - * @param e the element - * @return true if the element was not in the set - */ - protected boolean reverseAdd(@Nullable E e) { - boolean didNotAlreadyContain = !contains(e); - if (didNotAlreadyContain) { - addFirst(e); - } - return didNotAlreadyContain; - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/SequencedCollection.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/SequencedCollection.java deleted file mode 100644 index 19b9856b1..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/SequencedCollection.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * @(#)SequencedCollection.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.sequenced; - -import org.jhotdraw8.annotation.NonNull; - -import java.util.Collection; -import java.util.Iterator; -import java.util.NoSuchElementException; - -/** - * Interface for a collection with a well-defined iteration order. - *

- * References: - *

- *
JEP draft: Sequenced Collections
- *
java.ne
- *
- * - * @param the element type - */ -public interface SequencedCollection extends Collection { - /** - * Gets the first element. - * - * @return an element - * @throws java.util.NoSuchElementException if the collection is empty - */ - default E getFirst() { - return iterator().next(); - } - - /** - * Gets the last element. - * - * @return an element - * @throws java.util.NoSuchElementException if the collection is empty - */ - default E getLast() { - return _reversed().iterator().next(); - } - - /** - * Adds the specified element at the front of this collection. - * - * @param e an element - */ - void addFirst(E e); - - /** - * Adds the specified element at the end of this collection. - * - * @param e an element - */ - void addLast(E e); - - /** - * Returns a reversed-order view of this collection. - *

- * Modifications write through to the underlying collection. - * Changes to the underlying collection are visible in the reversed view. - * - * @return a reversed-order view of this collection - */ - @NonNull SequencedCollection _reversed(); - - /** - * Removes the element at the front of this collection. - * - * @return the first element - * @throws NoSuchElementException if this set is empty - */ - default E removeFirst() { - Iterator i = iterator(); - E e = i.next(); - i.remove(); - return e; - } - - /** - * Removes the element at the end of this collection. - * - * @return the last element - * @throws NoSuchElementException if this set is empty - */ - default E removeLast() { - Iterator i = _reversed().iterator(); - E e = i.next(); - i.remove(); - return e; - } -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/SequencedMap.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/SequencedMap.java deleted file mode 100644 index 91654a90c..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/SequencedMap.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * @(#)SequencedMap.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.sequenced; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; - -import java.util.Iterator; -import java.util.Map; - -/** - * Interface for a map with a well-defined iteration order. - *

- * References: - *

- *
JEP draft: Sequenced Collections
- *
java.ne
- *
- * - * @param the key type - * @param the value type - */ -public interface SequencedMap extends Map { - - /** - * Gets the first entry in this map or {@code null} if this map is empty. - * - * @return the first entry or {@code null} - * @throws java.util.NoSuchElementException if the map is empty - */ - default Map.@Nullable Entry firstEntry() { - return isEmpty() ? null : _sequencedEntrySet().iterator().next(); - } - - /** - * Gets the last entry in this map or {@code null} if this map is empty. - * - * @return the last entry or {@code null} - * @throws java.util.NoSuchElementException if the map is empty - */ - default Map.@Nullable Entry lastEntry() { - return isEmpty() ? null : _reversed()._sequencedEntrySet().iterator().next(); - } - - /** - * Returns a reversed-order view of this map. - *

- * Modifications write through to the underlying map. - * Changes to the underlying map are visible in the reversed view. - * - * @return a reversed-order view of this map - */ - @NonNull SequencedMap _reversed(); - - /** - * Removes and returns the first entry in this map or code {@code null} - * if the map is empty. - * - * @return the removed first entry of this map or code {@code null} - */ - default Map.Entry pollFirstEntry() { - Iterator> it = _sequencedEntrySet().iterator(); - if (it.hasNext()) { - Entry entry = it.next(); - it.remove(); - return entry; - } else { - return null; - } - } - - /** - * Removes and returns the first entry in this map or code {@code null} - * if the map is empty. - * - * @return the removed first entry of this map or code {@code null} - */ - default Map.Entry pollLastEntry() { - Iterator> it = _reversed()._sequencedEntrySet().iterator(); - if (it.hasNext()) { - Entry entry = it.next(); - it.remove(); - return entry; - } else { - return null; - } - } - - /** - * Creates an entry for the specified key and value and adds it to the front - * of the map if an entry for the specified key is not already present. - * If this map already contains an entry for the specified key, replaces the - * value and moves the entry to the front. - * - * @param k the key - * @param v the value - * @return the value previously associated with the key - */ - V putFirst(K k, V v); - - /** - * Creates an entry for the specified key and value and adds it to the tail - * of the map if an entry for the specified key is not already present. - * If this map already contains an entry for the specified key, replaces the - * value and moves the entry to the tail. - * - * @param k the key - * @param v the value - * @return the previous value associated with the key - */ - V putLast(K k, V v); - - /** - * Returns a {@link SequencedSet} view of the keys contained in this map. - * - * @return a {@link SequencedSet} view of the keys - */ - @NonNull - SequencedSet _sequencedKeySet(); - - /** - * Returns a {@link SequencedCollection} view of the values contained in - * this map. - * - * @return a {@link SequencedCollection} view of the values - */ - @NonNull - SequencedCollection _sequencedValues(); - - /** - * Returns a {@link SequencedSet} view of the entries contained in this map. - * - * @return a {@link SequencedSet} view of the entries - */ - @NonNull - SequencedSet> _sequencedEntrySet(); - - @Override - default V getOrDefault(Object key, V defaultValue) { - return Map.super.getOrDefault(key, defaultValue); - } - -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/SequencedSet.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/SequencedSet.java deleted file mode 100644 index 91d3dadd7..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/SequencedSet.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * @(#)SequencedSet.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.sequenced; - -import org.jhotdraw8.annotation.NonNull; - -import java.util.Set; - -/** - * Interface for a set with a well-defined iteration order. - *

- * References: - *

- *
JEP draft: Sequenced Collections
- *
java.ne
- *
- * - * @param the element type - */ -public interface SequencedSet extends Set, SequencedCollection { - @Override - @NonNull - SequencedSet _reversed(); -} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/package-info.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/package-info.java deleted file mode 100755 index fd99a2eb5..000000000 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/sequenced/package-info.java +++ /dev/null @@ -1,11 +0,0 @@ -/* - * @(#)package-info.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -/** - * Defines interfaces for sequenced collections. These interfaces will go away - * once we have migrated to a JDK that implements - * JDK-8280836. - */ -package org.jhotdraw8.collection.sequenced; diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/spliterator/ReadOnlyListSpliterator.java b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/spliterator/ReadOnlyListSpliterator.java index 709c451b9..42388f8c9 100755 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/spliterator/ReadOnlyListSpliterator.java +++ b/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/spliterator/ReadOnlyListSpliterator.java @@ -6,7 +6,7 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.readonly.ReadOnlyList; +import org.jhotdraw8.icollection.readonly.ReadOnlyList; import java.util.ListIterator; import java.util.Objects; diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractImmutableListTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractImmutableListTest.java deleted file mode 100644 index 1751c98bc..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractImmutableListTest.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.jhotdraw8.collection; - -public class AbstractImmutableListTest { -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractImmutableMapTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractImmutableMapTest.java deleted file mode 100644 index a206640f9..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractImmutableMapTest.java +++ /dev/null @@ -1,553 +0,0 @@ -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableMap; -import org.jhotdraw8.collection.readonly.ReadOnlyMap; -import org.jhotdraw8.collection.readonly.ReadOnlySet; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNotSame; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public abstract class AbstractImmutableMapTest { - - /** - * Creates a new empty instance. - */ - protected abstract @NonNull ImmutableMap newInstance(); - - - /** - * Creates a new instance with the specified map. - */ - protected abstract @NonNull ImmutableMap newInstance(@NonNull Map m); - - protected abstract @NonNull ImmutableMap newInstance(@NonNull ReadOnlyMap m); - - - protected abstract @NonNull ImmutableMap toClonedInstance(@NonNull ImmutableMap m); - - /** - * Creates a new instance with the specified map. - */ - protected abstract @NonNull ImmutableMap newInstance(@NonNull Iterable> m); - - public static Stream dataProvider() { - return Stream.of( - NO_COLLISION, ALL_COLLISION, SOME_COLLISION - ); - } - - private static final MapData NO_COLLISION = MapData.newData("no collisions", -1, 32, 100_000); - private static final MapData ALL_COLLISION = MapData.newData("all collisions", 0, 32, 100_000); - private static final MapData SOME_COLLISION = MapData.newData("some collisions", 0x55555555, 32, 100_000); - - - protected void assertEqualMap(ReadOnlyMap expected, ImmutableMap actual) { - assertEqualMap(expected.asMap(), actual); - } - - protected void assertEqualMap(Map expected, ImmutableMap actual) { - assertEquals(new LinkedHashSet<>(expected.values()), - new LinkedHashSet<>(actual.readOnlyValues().asCollection())); - assertEquals(expected.size(), actual.size()); - assertEquals(expected.isEmpty(), actual.isEmpty()); - assertEquals(expected.hashCode(), actual.hashCode()); - assertEquals(expected, actual.asMap()); - assertEquals(actual.asMap(), expected); - assertEquals(expected.entrySet(), actual.readOnlyEntrySet().asSet()); - assertEquals(expected.keySet(), actual.readOnlyKeySet().asSet()); - } - - protected void assertNotEqualMap(Map expected, ImmutableMap actual) { - assertNotEquals(expected, actual); - assertNotEquals(actual, expected); - assertNotEquals(expected.entrySet(), actual.readOnlyEntrySet().asSet()); - } - - @Test - public void testNewInstanceNoArgsShouldBeEmpty() { - ImmutableMap actual = newInstance(); - LinkedHashMap expected = new LinkedHashMap<>(); - assertEqualMap(expected, actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testNewInstanceMapArgsShouldBeEqualToArg(MapData data) { - ImmutableMap actual = newInstance(data.a().asMap()); - assertEqualMap(data.a(), actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testNewInstanceMapArgsOfSameTypeShouldBeEqualToArg(MapData data) { - ImmutableMap actual1 = newInstance(data.a().asMap()); - ImmutableMap actual = newInstance(actual1); - assertEqualMap(data.a(), actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testNewInstanceReadOnlyMapArgShouldBeEqualToARg(MapData data) { - ImmutableMap actual = newInstance(data.a()); - assertEqualMap(data.a(), actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testNewInstanceIterableArgShouldBeEqualToArg(MapData data) { - ImmutableMap actual = newInstance(data.a().readOnlyEntrySet()); - assertEqualMap(data.a(), actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testCopyClearShouldYieldEmptyMap(MapData data) { - ImmutableMap instance = newInstance(data.a()); - assertNotEqualMap(Collections.emptyMap(), instance); - ImmutableMap instance2 = instance.clear(); - assertNotSame(instance, instance2); - assertEqualMap(Collections.emptyMap(), instance2); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testCopyClearShouldBeIdempotent(MapData data) { - ImmutableMap instance = newInstance(data.a()); - assertNotEqualMap(Collections.emptyMap(), instance); - instance = instance.clear(); - assertEqualMap(Collections.emptyMap(), instance); - ImmutableMap instance2 = instance.clear(); - assertSame(instance, instance2); - assertEqualMap(Collections.emptyMap(), instance2); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testCloneShouldYieldEqualMap(MapData data) { - ImmutableMap instance = newInstance(data.a()); - ImmutableMap clone = toClonedInstance(instance); - assertEqualMap(data.a(), clone); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testContainsKeyShouldYieldExpectedValue(MapData data) { - ImmutableMap instance = newInstance(data.a()); - for (HashCollider k : data.a().readOnlyKeySet()) { - assertTrue(instance.containsKey(k)); - } - for (HashCollider k : data.c().readOnlyKeySet()) { - assertFalse(instance.containsKey(k)); - } - assertFalse(instance.containsKey(new Object())); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testReadOnlyEntrySetContainsShouldYieldExpectedValue(MapData data) { - ImmutableMap instance = newInstance(data.a()); - for (Map.Entry e : data.a().readOnlyEntrySet()) { - assertTrue(instance.readOnlyEntrySet().contains(e)); - } - for (Map.Entry e : data.b().readOnlyEntrySet()) { - assertFalse(instance.readOnlyEntrySet().contains(e)); - } - for (Map.Entry e : data.c().readOnlyEntrySet()) { - assertFalse(instance.readOnlyEntrySet().contains(e)); - } - assertFalse(instance.readOnlyEntrySet().contains(new Object())); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testIteratorRemoveShouldThrowException(MapData data) { - ImmutableMap instance = newInstance(data.a()); - Iterator i = instance.readOnlyKeySet().iterator(); - assertThrows(Exception.class, i::remove); - Iterator k = instance.readOnlyValues().iterator(); - assertThrows(Exception.class, k::remove); - Iterator> j = instance.readOnlyEntrySet().iterator(); - assertThrows(Exception.class, j::remove); - } - - @SuppressWarnings("unchecked") - @ParameterizedTest - @MethodSource("dataProvider") - public void testSerializationShouldYieldSameMap(MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a()); - assertEqualMap(data.a(), instance); - if (instance instanceof Serializable) { - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - try (ObjectOutputStream out = new ObjectOutputStream(buf)) { - out.writeObject(instance); - } - ImmutableMap deserialized; - try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buf.toByteArray()))) { - deserialized = (ImmutableMap) in.readObject(); - } - assertEqualMap(data.a(), deserialized); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testEqualWithThisShouldYieldTrue(MapData data) { - ImmutableMap instance = newInstance(data.a()); - assertEquals(instance, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testEqualsWithCloneWithUpdatedEntriesShouldYieldFalse(MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a()); - ImmutableMap instance2 = toClonedInstance(instance); - assertEquals(instance, instance2); - - // WHEN instance3 has not the same size as instance2 - ImmutableMap instance3 = instance2.putAll(data.b().asMap()); - assertNotEquals(instance2.size(), instance3.size()); - assertNotSame(instance2, instance3); - assertNotEquals(instance, instance3); - assertNotEquals(instance2, instance3); - - // WHEN instance4 has the same size as instance - assertEquals(data.a().size(), data.b().size()); - ImmutableMap instance4 = newInstance(data.b()); - assertNotEquals(instance, instance4); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testCopyPutWithNewKeyShouldReturnNewInstance(MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a); - LinkedHashMap expected = new LinkedHashMap<>(data.a().asMap()); - for (Map.Entry e : data.c) { - ImmutableMap instance2 = instance.put(e.getKey(), e.getValue()); - assertNotSame(instance, instance2); - expected.put(e.getKey(), e.getValue()); - assertEqualMap(expected, instance2); - instance = instance2; - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testCopyPutWithContainedKeyButNewValueShouldReturnNewInstance(MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a()); - LinkedHashMap expected = new LinkedHashMap<>(data.a().asMap()); - for (Map.Entry e : data.b) { - ImmutableMap instance2 = instance.put(e.getKey(), e.getValue()); - assertNotSame(instance, instance2); - assertEqualMap(expected, instance); - expected.put(e.getKey(), e.getValue()); - assertEqualMap(expected, instance2); - instance = instance2; - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testCopyRemoveWithNewKeyShouldReturnThis(MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a); - for (Map.Entry e : data.c) { - assertSame(instance, instance.remove(e.getKey())); - assertEqualMap(data.a.asMap(), instance); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testCopyRemoveWithContainedKeyShouldReturnNewInstance(MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a); - LinkedHashMap expected = new LinkedHashMap<>(data.a().asMap()); - for (Map.Entry e : data.a) { - ImmutableMap instance2 = instance.remove(e.getKey()); - assertNotSame(instance, instance2); - assertEqualMap(expected, instance); - expected.remove(e.getKey()); - assertEqualMap(expected, instance2); - instance = instance2; - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testEntrySetContainsExpectedEntries(MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a); - ReadOnlySet> entrySet = instance.readOnlyEntrySet(); - for (Map.Entry e : data.a) { - assertTrue(entrySet.contains(e)); - } - for (Map.Entry e : data.b) { - assertFalse(entrySet.contains(e)); - } - for (Map.Entry e : data.c) { - assertFalse(entrySet.contains(e)); - } - assertTrue(entrySet.containsAll(data.a.readOnlyEntrySet().asSet())); - assertFalse(entrySet.containsAll(data.b.readOnlyEntrySet().asSet())); - assertFalse(entrySet.containsAll(data.c.readOnlyEntrySet().asSet())); - LinkedHashSet> abc = new LinkedHashSet<>(data.a.readOnlyEntrySet().asSet()); - abc.addAll(data.b.readOnlyEntrySet().asSet()); - abc.addAll(data.c.readOnlyEntrySet().asSet()); - assertFalse(entrySet.containsAll(abc)); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testEntryIteratorShouldYieldExpectedEntries(MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a); - List> actualList = new ArrayList<>(); - LinkedHashMap actualMap = new LinkedHashMap<>(); - instance.readOnlyEntrySet().iterator().forEachRemaining(actualList::add); - instance.readOnlyEntrySet().iterator().forEachRemaining(e -> actualMap.put(e.getKey(), e.getValue())); - assertEquals(data.a.size(), actualList.size()); - assertEqualMap(data.a, newInstance(actualMap)); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testCopyPutWithContainedEntryShouldReturnThis(MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a()); - LinkedHashMap expected = new LinkedHashMap<>(data.a().asMap()); - for (Map.Entry e : data.a) { - ImmutableMap instance2 = instance.put(e.getKey(), e.getValue()); - assertSame(instance, instance2); - assertEqualMap(expected, instance2); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testCopyPutAllWithContainedEntriesShouldReturnThis(MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a()); - ImmutableMap instance2 = instance.putAll(data.a().asMap()); - assertSame(instance, instance2); - assertEqualMap(data.a(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testCopyPutAllWithNewEntriesShouldReturnNewInstance(MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a()); - ImmutableMap instance2 = instance.putAll(data.c().asMap()); - assertNotSame(instance, instance2); - Map expected = new LinkedHashMap<>(data.a().asMap()); - assertEqualMap(expected, instance); - expected.putAll(data.c().asMap()); - assertEqualMap(expected, instance2); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testCopyPutAllWithContainedKeysButNewValuesShouldReturnNewInstance(MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a()); - ImmutableMap instance2 = instance.putAll(data.b().asMap()); - assertNotSame(instance, instance2); - Map expected = new LinkedHashMap<>(data.a().asMap()); - assertEqualMap(expected, instance); - expected.putAll(data.b().asMap()); - assertEqualMap(expected, instance2); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testCopyPutAllWithSelfShouldReturnThis(MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a()); - ImmutableMap instance2 = instance.putAll(instance); - assertSame(instance, instance2); - assertEqualMap(data.a, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testEqualsWithObjectShouldYieldFalse(MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a()); - assertNotEquals(instance, new Object()); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testGetOrDefaultWithContainedKeyShouldYieldValue(MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a()); - HashCollider defaultValue = new HashCollider(7, -1); - for (Map.Entry e : data.a()) { - assertEquals(e.getValue(), instance.getOrDefault(e.getKey(), defaultValue)); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testGetOrDefaultWithNonContainedKeyShouldYieldDefault(MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a()); - HashCollider defaultValue = new HashCollider(7, -1); - for (Map.Entry e : data.c()) { - assertEquals(defaultValue, instance.getOrDefault(e.getKey(), defaultValue)); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testCopyPutAllWithSomeNewKeyShouldReturnNewInstance(MapData data) throws Exception { - ArrayList> listB = new ArrayList<>(data.b.readOnlyEntrySet().asSet()); - ArrayList> listC = new ArrayList<>(data.c.readOnlyEntrySet().asSet()); - Map m = new LinkedHashMap<>(data.a.asMap()); - for (Map.Entry entry : listB.subList(0, listB.size() / 2)) { - m.put(entry.getKey(), entry.getValue()); - } - for (Map.Entry entry : listC.subList(0, listC.size() / 2)) { - m.put(entry.getKey(), entry.getValue()); - } - ImmutableMap instance = newInstance(data.a); - ImmutableMap instance2 = instance.putAll(m); - assertNotSame(instance, instance2); - LinkedHashMap expected = new LinkedHashMap<>(data.a.asMap()); - assertEqualMap(expected, instance); - expected.putAll(m); - assertEqualMap(expected, instance2); - } - - @SuppressWarnings("SimplifiableAssertion") - @ParameterizedTest - @MethodSource("dataProvider") - public void testEqualsWithNullShouldYieldFalse(@NonNull MapData data) { - ImmutableMap instance = newInstance(data.a()); - assertFalse(instance.equals(null)); - } - - - @ParameterizedTest - @MethodSource("dataProvider") - public void testToStringShouldContainAllEntries(@NonNull MapData data) { - ImmutableMap instance = newInstance(); - assertEquals("{}", instance.toString()); - - instance = instance.putAll(data.a.asMap()); - String str = instance.toString(); - assertEquals('{', str.charAt(0)); - assertEquals('}', str.charAt(str.length() - 1)); - LinkedHashSet actual = new LinkedHashSet<>(Arrays.asList(str.substring(1, str.length() - 1).split(", "))); - Set expected = new LinkedHashSet<>(); - data.a.iterator().forEachRemaining(e -> expected.add(e.toString())); - assertEquals(expected, actual); - } - - - @ParameterizedTest - @MethodSource("dataProvider") - public void testCopyRetainAllWithContainedKeysShouldReturnThis(@NonNull MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a()); - ImmutableMap instance2 = instance.retainAll(data.a().asMap().keySet()); - assertSame(instance, instance2); - assertEqualMap(data.a(), instance2); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testCopyRetainAllWithSomeContainedKeysShouldReturnNewInstance(@NonNull MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a()); - ImmutableMap instance2 = instance.retainAll(data.someAPlusSomeB().asMap().keySet()); - assertNotSame(instance, instance2); - LinkedHashMap expected = new LinkedHashMap<>(data.a().asMap()); - expected.keySet().retainAll(data.someAPlusSomeB().asMap().keySet()); - assertEqualMap(expected, instance2); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testCopyRetainAllWithEmptySetShouldReturnNewInstance(@NonNull MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a()); - ImmutableMap instance2 = instance.retainAll(Collections.emptySet()); - assertNotSame(instance, instance2); - assertEqualMap(data.a(), instance); - assertEqualMap(Collections.emptyMap(), instance2); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testCopyRetainAllOfEmptyMapShouldReturnThis(@NonNull MapData data) throws Exception { - ImmutableMap instance = newInstance(); - ImmutableMap instance2 = instance.retainAll(data.a().asMap().keySet()); - assertSame(instance, instance2); - assertEqualMap(Collections.emptyMap(), instance2); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testCopyRemoveAllOfEmptyMapShouldReturnThis(@NonNull MapData data) throws Exception { - ImmutableMap instance = newInstance(); - assertSame(instance, instance.removeAll(data.a.readOnlyKeySet().asSet())); - assertEqualMap(Collections.emptyMap(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testCopyRemoveAllWithEmptyMapShouldReturnThis(@NonNull MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a); - assertSame(instance, instance.removeAll(Collections.emptySet())); - assertEqualMap(data.a(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testCopyRemoveAllWithContainedKeyShouldReturnNewInstance(@NonNull MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a); - ImmutableMap instance2 = instance.removeAll(data.a.readOnlyKeySet().asSet()); - assertNotSame(instance, instance2); - assertEqualMap(data.a, instance); - assertEqualMap(Collections.emptyMap(), instance2); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testCopyRemoveAllWithSomeContainedKeyShouldReturnNewInstance(@NonNull MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a); - ImmutableMap instance2 = instance.removeAll(data.someAPlusSomeB().readOnlyKeySet().asSet()); - assertNotSame(instance, instance2); - LinkedHashMap expected = new LinkedHashMap<>(data.a.asMap()); - assertEqualMap(expected, instance); - expected.keySet().removeAll(data.someAPlusSomeB().readOnlyKeySet().asSet()); - assertEqualMap(expected, instance2); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testGetOfEntryWithNullValueShouldYieldNull(@NonNull MapData data) throws Exception { - ImmutableMap instance = newInstance(data.a()); - LinkedHashMap expected = new LinkedHashMap<>(data.a.asMap()); - HashCollider key = new HashCollider(42, -1); - ImmutableMap instance2 = instance.put(key, null); - assertNotSame(instance, instance2); - expected.put(key, null); - assertTrue(instance2.containsKey(key)); - assertNull(instance2.get(key)); - assertEqualMap(expected, instance2); - } - -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractImmutableSequencedMapTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractImmutableSequencedMapTest.java deleted file mode 100644 index 2a969d997..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractImmutableSequencedMapTest.java +++ /dev/null @@ -1,226 +0,0 @@ -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableMap; -import org.jhotdraw8.collection.immutable.ImmutableSequencedMap; -import org.jhotdraw8.collection.readonly.ReadOnlyMap; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; - -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public abstract class AbstractImmutableSequencedMapTest extends AbstractImmutableMapTest { - @Override - protected abstract @NonNull ImmutableSequencedMap newInstance(); - - @Override - protected abstract @NonNull ImmutableSequencedMap newInstance(@NonNull Map m); - - @Override - protected abstract @NonNull ImmutableSequencedMap newInstance(@NonNull ReadOnlyMap m); - - @Override - protected abstract @NonNull ImmutableSequencedMap toClonedInstance(@NonNull ImmutableMap m); - - @Override - protected abstract @NonNull ImmutableSequencedMap newInstance(@NonNull Iterable> m); - - - @ParameterizedTest - @MethodSource("dataProvider") - public void putFirstWithContainedEntryShouldMoveEntryToFirst(MapData data) throws Exception { - ImmutableSequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - assertEqualSequence(expected, instance, "initial"); - for (Map.Entry e : data.a()) { - instance = instance.putFirst(e.getKey(), e.getValue()); - expected.remove(e); - expected.add(0, e); - assertEqualSequence(expected, instance, "putFirst"); - assertEquals(e, instance.firstEntry()); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void putFirstWithNewElementShouldMoveElementToFirst(MapData data) throws Exception { - ImmutableSequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - for (Map.Entry e : data.c()) { - instance = instance.putFirst(e.getKey(), e.getValue()); - Map.Entry firstEntry = instance.firstEntry(); - assertEquals(e, firstEntry); - assertNotNull(firstEntry); - assertEquals(e.getKey(), firstEntry.getKey()); - expected.remove(e); - expected.add(0, e); - assertEqualSequence(expected, instance, "putFirst"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void putLastWithContainedElementShouldMoveElementToLast(MapData data) throws Exception { - ImmutableSequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - for (Map.Entry e : data.a()) { - instance = instance.putLast(e.getKey(), e.getValue()); - Map.Entry lastEntry = instance.lastEntry(); - assertEquals(e, lastEntry); - assertNotNull(lastEntry); - assertEquals(e.getKey(), lastEntry.getKey()); - expected.remove(e); - expected.add(e); - assertEqualSequence(expected, instance, "putLast"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void putLastWithNewElementShouldMoveElementToLast(MapData data) throws Exception { - ImmutableSequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - for (Map.Entry e : data.c()) { - instance = instance.putLast(e.getKey(), e.getValue()); - assertEquals(e, instance.lastEntry()); - expected.remove(e); - expected.add(e); - assertEqualSequence(expected, instance, "putLast"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void putWithContainedElementShouldNotMoveElementToLast(MapData data) throws Exception { - ImmutableSequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - for (Map.Entry e : data.a()) { - instance = instance.put(e.getKey(), e.getValue()); - assertEquals(expected.get(expected.size() - 1), instance.lastEntry()); - assertEqualSequence(expected, instance, "put"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeWithLastElementShouldNotChangeSequence(MapData data) throws Exception { - ImmutableSequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - while (!expected.isEmpty()) { - Map.Entry e = expected.remove(expected.size() - 1); - instance = instance.remove(e.getKey()); - assertEqualSequence(expected, instance, "remove(lastElement)"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeFirstShouldNotChangeSequence(MapData data) throws Exception { - ImmutableSequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - while (!expected.isEmpty()) { - Map.Entry e = expected.remove(0); - instance = instance.removeFirst(); - assertEqualSequence(expected, instance, "removeFirst"); - } - } - - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeLastShouldNotChangeSequence(MapData data) throws Exception { - ImmutableSequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - while (!expected.isEmpty()) { - expected.remove(expected.size() - 1); - instance = instance.removeLast(); - assertEqualSequence(expected, instance, "removeLast"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeWithFirstElementShouldNotChangeSequence(MapData data) throws Exception { - ImmutableSequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - while (!expected.isEmpty()) { - Map.Entry e = expected.remove(0); - instance = instance.remove(e.getKey()); - assertEqualSequence(expected, instance, "remove(firstElement)"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeWithMiddleElementShouldNotChangeSequence(MapData data) throws Exception { - ImmutableSequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - while (!expected.isEmpty()) { - Map.Entry e = expected.remove(expected.size() / 2); - instance = instance.remove(e.getKey()); - assertEqualSequence(expected, instance, "removeMiddle"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void putWithNewElementShouldMoveElementToLast(MapData data) throws Exception { - ImmutableSequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - for (Map.Entry e : data.c()) { - instance = instance.put(e.getKey(), e.getValue()); - assertEquals(e, instance.lastEntry()); - expected.remove(e); - expected.add(e); - assertEqualSequence(expected, instance, "add"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void putNewValueForExistingElementShouldNotChangeSequence(MapData data) throws Exception { - ImmutableSequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - ArrayList indices = new ArrayList<>(data.a().size()); - for (int i = 0; i < data.a().size(); i++) { - indices.add(i); - } - Collections.shuffle(indices); - for (int i : indices) { - HashCollider newValue = new HashCollider(i, -1); - Map.Entry oldEntry = expected.get(i); - var newEntry = (AbstractMap.SimpleImmutableEntry) new AbstractMap.SimpleImmutableEntry<>(oldEntry.getKey(), newValue); - - instance = instance.put(oldEntry.getKey(), newValue); - expected.set(i, newEntry); - assertEqualSequence(expected, instance, "put " + i + " oldValue: " + oldEntry + " newValue: " + newEntry); - } - } - - protected void assertEqualSequence(Collection> expected, ImmutableSequencedMap actual, String message) { - ArrayList> expectedList = new ArrayList<>(expected); - assertEquals(expectedList, new ArrayList<>(actual.readOnlySequencedEntrySet().asSet()), message); - - if (!expected.isEmpty()) { - assertEquals(expectedList.get(0), actual.firstEntry(), message); - assertEquals(expectedList.get(0), actual.readOnlySequencedEntrySet().iterator().next(), message); - assertEquals(expectedList.get(expectedList.size() - 1), actual.lastEntry(), message); - assertEquals(expectedList.get(expectedList.size() - 1), actual.readOnlyReversed().readOnlySequencedEntrySet().iterator().next(), message); - } - - LinkedHashMap x = new LinkedHashMap<>(); - for (Map.Entry e : expected) { - x.put(e.getKey(), e.getValue()); - } - assertEquals(x.toString(), actual.toString(), message); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractImmutableSequencedSetTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractImmutableSequencedSetTest.java deleted file mode 100644 index ce4f2bef3..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractImmutableSequencedSetTest.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableSequencedSet; -import org.jhotdraw8.collection.immutable.ImmutableSet; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedSet; -import org.jhotdraw8.collection.sequenced.SequencedSet; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotSame; -import static org.junit.jupiter.api.Assertions.assertThrows; - -public abstract class AbstractImmutableSequencedSetTest extends AbstractImmutableSetTest { - @Override - protected abstract @NonNull ImmutableSequencedSet newInstance(); - - @Override - protected abstract @NonNull SequencedSet toMutableInstance(ImmutableSet m); - - @Override - protected abstract @NonNull ImmutableSequencedSet toImmutableInstance(Set m); - - @Override - protected abstract @NonNull ImmutableSequencedSet toClonedInstance(ImmutableSet m); - - @Override - protected abstract @NonNull ImmutableSequencedSet newInstance(Iterable m); - - - @ParameterizedTest - @MethodSource("dataProvider") - public void copyRemoveLastWithEmptySetShouldThrowNoSuchElementException(@NonNull SetData data) throws Exception { - ImmutableSequencedSet instance = newInstance(data.a()); - instance = instance.removeAll(data.a().asSet()); - assertThrows(NoSuchElementException.class, instance::removeLast); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeLastShouldNotChangeSequence(@NonNull SetData data) throws Exception { - ImmutableSequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - assertEqualSequence(expected, instance, "new instance(data.a())"); - while (!expected.isEmpty()) { - ImmutableSequencedSet instance2 = instance.removeLast(); - assertNotSame(instance, instance2); - expected.remove(expected.size() - 1); - assertEqualSequence(expected, instance2, "removeLast"); - instance = instance2; - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeLastStartingWithEmptySetShouldNotChangeSequence(@NonNull SetData data) throws Exception { - ImmutableSequencedSet instance = newInstance(); - instance = instance.addAll(data.a.asSet()); - List expected = new ArrayList<>(data.a().asSet()); - while (!expected.isEmpty()) { - ImmutableSequencedSet instance2 = instance.removeLast(); - assertNotSame(instance, instance2); - expected.remove(expected.size() - 1); - assertEqualSequence(expected, instance2, "removeLast"); - instance = instance2; - } - } - - - protected void assertEqualSequence(Collection expected, ReadOnlySequencedSet actual, String message) { - ArrayList expectedList = new ArrayList<>(expected); - assertEquals(expectedList, new ArrayList<>(actual.asSet()), message); - if (!expected.isEmpty()) { - assertEquals(expectedList.get(0), actual.getFirst(), message); - assertEquals(expectedList.get(0), actual.iterator().next(), message); - assertEquals(expectedList.get(expectedList.size() - 1), actual.getLast(), message); - //assertEquals(expectedList.get(expectedList.size() - 1), actual.reversed().iterator().next(), message); - } - assertEquals(expected.toString(), actual.toString(), message); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractImmutableSetTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractImmutableSetTest.java deleted file mode 100644 index 7e32cb9c4..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractImmutableSetTest.java +++ /dev/null @@ -1,645 +0,0 @@ -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableSet; -import org.jhotdraw8.collection.readonly.ReadOnlySet; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; - -import java.io.*; -import java.util.*; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.*; - -public abstract class AbstractImmutableSetTest { - - /** - * Creates a new empty instance. - */ - protected abstract @NonNull ImmutableSet newInstance(); - - - protected abstract @NonNull Set toMutableInstance(ImmutableSet m); - - protected abstract @NonNull ImmutableSet toImmutableInstance(Set m); - - protected abstract @NonNull ImmutableSet toClonedInstance(ImmutableSet m); - - /** - * Creates a new instance with the specified map. - */ - protected abstract @NonNull ImmutableSet newInstance(Iterable m); - - public static @NonNull Stream dataProvider() { - return Stream.of( - NO_COLLISION_NICE_KEYS, NO_COLLISION, ALL_COLLISION, SOME_COLLISION - ); - } - - private static final SetData NO_COLLISION_NICE_KEYS = SetData.newNiceData("no collisions nice keys", -1, 32, 100_000); - private static final SetData NO_COLLISION = SetData.newData("no collisions", -1, 32, 100_000); - private static final SetData ALL_COLLISION = SetData.newData("all collisions", 0, 32, 100_000); - private static final SetData SOME_COLLISION = SetData.newData("some collisions", 0x55555555, 32, 100_000); - - private static int createNewValue(@NonNull Random rng, @NonNull Set usedValues, int bound) { - int value; - int count = 0; - do { - value = rng.nextInt(bound); - count++; - if (count >= bound) { - throw new RuntimeException("error in rng"); - } - } while (!usedValues.add(value)); - return value; - } - - - protected void assertEqualSet(@NonNull ReadOnlySet expected, @NonNull ImmutableSet actual) { - assertEqualSet(expected.asSet(), actual); - } - - protected void assertEqualSet(@NonNull Set expected, @NonNull ImmutableSet actual) { - Set expectedValues = new LinkedHashSet<>(expected); - Set actualValues = new LinkedHashSet<>(actual.asSet()); - assertEquals(expectedValues, actualValues); - - for (var e : expected) { - assertTrue(actual.contains(e), "must contain " + e); - } - - assertEquals(expected.size(), actual.size()); - assertEquals(expected.isEmpty(), actual.isEmpty()); - assertEquals(expected.hashCode(), actual.hashCode()); - assertEquals(expected, actual.asSet()); - assertEquals(actual.asSet(), expected); - } - - protected void assertNotEqualSet(Set expected, @NonNull ImmutableSet actual) { - assertNotEquals(expected, actual.asSet()); - assertNotEquals(actual.asSet(), expected); - } - - @Test - public void newInstanceNoArgsShouldBeEmpty() { - ImmutableSet actual = newInstance(); - LinkedHashSet expected = new LinkedHashSet<>(); - assertEqualSet(expected, actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void newInstanceSetArgsShouldBeEqualToSet(@NonNull SetData data) { - ImmutableSet actual = newInstance(data.a().asSet()); - assertEqualSet(data.a().asSet(), actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void newInstanceSetArgsOfSameTypeShouldBeEqualToSet(@NonNull SetData data) { - ImmutableSet actual1 = newInstance(data.a().asSet()); - ImmutableSet actual = newInstance(actual1); - assertEqualSet(data.a().asSet(), actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void newInstanceReadOnlySetArgShouldBeEqualToArg(@NonNull SetData data) { - ImmutableSet actual = newInstance(data.a()); - assertEqualSet(data.a().asSet(), actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void newInstanceReadOnlySetArgWithThisShouldBeEqualToArg(@NonNull SetData data) { - ImmutableSet actual = newInstance(data.a()); - ImmutableSet actual2 = newInstance(actual); - assertEqualSet(data.a().asSet(), actual2); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void newInstanceReadOnlySetArgsWithMutableSetArgsOfSameTypeShouldBeEqualToSet(@NonNull SetData data) { - ImmutableSet actual1 = newInstance(data.a()); - ImmutableSet actual = newInstance(toMutableInstance(actual1)); - assertEqualSet(data.a().asSet(), actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void clearShouldYieldEmptySet(@NonNull SetData data) { - ImmutableSet actual = newInstance(data.a()); - assertNotEqualSet(Collections.emptySet(), actual); - ImmutableSet actual2 = actual.clear(); - assertNotSame(actual, actual2); - assertEqualSet(Collections.emptySet(), actual2); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void clearShouldBeIdempotent(@NonNull SetData data) { - ImmutableSet instance = newInstance(data.a()); - assertNotEqualSet(Collections.emptySet(), instance); - ImmutableSet instance2 = instance.clear(); - assertEqualSet(Collections.emptySet(), instance2); - assertNotSame(instance, instance2); - - ImmutableSet instance3 = instance2.clear(); - assertSame(instance2, instance3); - assertEqualSet(Collections.emptySet(), instance3); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void cloneShouldYieldEqualSet(@NonNull SetData data) { - ImmutableSet instance = newInstance(data.a()); - ImmutableSet clone = toClonedInstance(instance); - assertEqualSet(data.a().asSet(), clone); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void containsShouldYieldExpectedValue(@NonNull SetData data) { - ImmutableSet instance = newInstance(data.a()); - for (HashCollider k : data.a()) { - assertTrue(instance.contains(k)); - } - for (HashCollider k : data.c()) { - assertFalse(instance.contains(k)); - } - assertFalse(instance.contains(new Object())); - } - - - @ParameterizedTest - @MethodSource("dataProvider") - public void iteratorRemoveShouldThrowUnsupportedOperationException(@NonNull SetData data) { - ImmutableSet instance = newInstance(data.a()); - Set expected = new LinkedHashSet<>(data.a().asSet()); - List toRemove = new ArrayList<>(new HashSet<>(data.a().asSet())); - outer: - while (!toRemove.isEmpty() && !expected.isEmpty()) { - for (Iterator i = instance.iterator(); i.hasNext(); ) { - HashCollider k = i.next(); - if (k.equals(toRemove.get(0))) { - assertThrows(UnsupportedOperationException.class, i::remove); - toRemove.remove(0); - assertEqualSet(expected, instance); - continue outer; - } - } - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void iteratorRemoveShouldThrowException(@NonNull SetData data) { - ImmutableSet instance = newInstance(data.a()); - Iterator i = instance.iterator(); - assertThrows(Exception.class, i::remove); - Iterator k = instance.iterator(); - assertThrows(Exception.class, k::remove); - } - - @SuppressWarnings("unchecked") - @ParameterizedTest - @MethodSource("dataProvider") - public void serializationShouldYieldSameSet(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a()); - if (instance instanceof Serializable) { - assertEqualSet(data.a().asSet(), instance); - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - try (ObjectOutputStream out = new ObjectOutputStream(buf)) { - out.writeObject(instance); - } - ImmutableSet deserialized; - try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buf.toByteArray()))) { - deserialized = (ImmutableSet) in.readObject(); - } - assertEqualSet(data.a().asSet(), deserialized); - } - } - - @SuppressWarnings({"ConstantConditions", "SimplifiableAssertion"}) - @ParameterizedTest - @MethodSource("dataProvider") - public void equalsWithNullShouldYieldFalse(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a()); - assertFalse(instance.equals(null)); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void equalWithThisShouldYieldTrue(@NonNull SetData data) { - ImmutableSet instance = newInstance(data.a()); - assertEquals(instance, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void equalsWithCloneShouldYieldTrue(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a()); - ImmutableSet clone = toClonedInstance(instance); - assertEquals(data.a().asSet(), clone.asSet()); - assertEquals(instance, clone); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addNullContainsNullShouldReturnTrue(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(); - var expected = new LinkedHashSet(); - expected.add(null); - var actual = instance.add(null); - assertFalse(instance.contains(null)); - assertTrue(actual.contains(null)); - assertEqualSet(expected, actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addAllNullContainsNullShouldReturnTrue(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(); - var expected = new LinkedHashSet(); - expected.addAll(Collections.singleton(null)); - var actual = instance.addAll(Collections.singleton(null)); - assertFalse(instance.contains(null)); - assertTrue(actual.contains(null)); - assertEqualSet(expected, actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addWithNewElementShouldReturnNewInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - Set expected = new LinkedHashSet<>(data.a.asSet()); - for (HashCollider e : data.c) { - ImmutableSet instance2 = instance.add(e); - assertNotSame(instance, instance2); - instance = instance2; - expected.add(e); - assertEqualSet(expected, instance); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addWithContainedElementShouldReturnSameInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - Set expected = new LinkedHashSet<>(data.a.asSet()); - for (HashCollider e : data.a) { - ImmutableSet instance2 = instance.add(e); - assertSame(instance, instance2); - assertEqualSet(expected, instance); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addAllWithNewElementsShouldReturnNewInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - ImmutableSet instance2 = instance.addAll(data.c); - assertNotSame(instance, instance2); - LinkedHashSet expected = new LinkedHashSet<>(data.a.asSet()); - expected.addAll(data.c.asSet()); - assertEquals(expected, instance2.asSet()); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addAllWithContainedElementsShouldReturnSameInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - ImmutableSet instance2 = instance.addAll(data.a.asSet()); - assertSame(instance, instance2); - assertEquals(data.a.asSet(), instance2.asSet()); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addAllWithSelfShouldReturnSameInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - ImmutableSet instance2 = instance.addAll(instance); - assertSame(instance, instance2); - assertEquals(data.a.asSet(), instance2.asSet()); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addAllWithCloneShouldReturnSameInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - ImmutableSet clone = toClonedInstance(instance); - assertNotSame(instance, clone); - ImmutableSet instance3 = instance.addAll(clone); - assertSame(instance, instance3); - assertEquals(data.a.asSet(), instance3.asSet()); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addAllWithCloneToMutableShouldReturnSameInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - ImmutableSet instance2 = toClonedInstance(instance); - ImmutableSet instance3 = instance.addAll(instance2.toMutable()); - assertSame(instance, instance3); - assertEquals(data.a.asSet(), instance3.asSet()); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void equalsWithObjectShouldYieldFalse(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a()); - assertNotEquals(instance, new Object()); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeWithNewElementShouldReturnSameInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - for (HashCollider e : data.c) { - ImmutableSet instance2 = instance.remove(e); - assertSame(instance, instance2); - assertEqualSet(data.a, instance); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeWithContainedKeyShouldReturnNewInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - LinkedHashSet expected = new LinkedHashSet<>(data.a().asSet()); - for (HashCollider e : data.a) { - expected.remove(e); - ImmutableSet instance2 = instance.remove(e); - assertNotSame(instance, instance2); - instance = instance2; - assertEqualSet(expected, instance); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeAllWithNewKeyShouldReturnSameInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - ImmutableSet instance2 = instance.removeAll(data.c.asSet()); - assertSame(instance, instance2); - assertEqualSet(data.a, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeAllWithContainedKeyShouldReturnNewInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - ImmutableSet instance2 = instance.removeAll(data.a.asSet()); - assertNotSame(instance, instance2); - assertEqualSet(Collections.emptySet(), instance2); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeAllWithCloneShouldReturnNewInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - ImmutableSet clone = toClonedInstance(instance); - assertNotSame(instance, clone); - ImmutableSet instance2 = instance.removeAll(clone); - assertNotSame(instance, instance2); - assertEqualSet(Collections.emptySet(), instance2); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeAllWithReadOnlySetWithSomeContainedKeyShouldReturnNewInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - ImmutableSet instance2 = instance.removeAll(data.someAPlusSomeB); - assertNotSame(instance, instance2); - assertEqualSet(data.a, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeAllWithSetWithSomeContainedKeyShouldReturnNewInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - ImmutableSet instance2 = instance.removeAll(data.someAPlusSomeB.asSet()); - assertNotSame(instance, instance2); - assertEqualSet(data.a, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeAllWithSameTypeWithSomeContainedKeyShouldReturnNewInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - ImmutableSet instance2 = instance.removeAll(newInstance(data.someAPlusSomeB)); - assertNotSame(instance, instance2); - assertEqualSet(data.a, instance); - LinkedHashSet expected = new LinkedHashSet<>(data.a.asSet()); - expected.removeAll(data.someAPlusSomeB().asSet()); - assertEqualSet(expected, instance2); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addAllWithSomeNewKeysShouldReturnNewInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - ImmutableSet instance2 = instance.addAll(data.someAPlusSomeB()); - assertNotSame(instance, instance2); - LinkedHashSet expected = new LinkedHashSet<>(data.a.asSet()); - assertEqualSet(expected, instance); - expected.addAll(data.someAPlusSomeB().asSet()); - assertEqualSet(expected, instance2); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addAllWithSameTypeAndSomeNewKeysShouldReturnNewInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - - ArrayList listA = new ArrayList<>(data.a.asSet()); - ArrayList listC = new ArrayList<>(data.c.asSet()); - - ImmutableSet instance2 = newInstance(); - instance2 = instance2.addAll(listA.subList(0, listA.size() / 2)); - instance2 = instance2.addAll(listC.subList(0, listC.size() / 2)); - - LinkedHashSet expected = new LinkedHashSet<>(listA); - LinkedHashSet expected2 = new LinkedHashSet<>(); - expected2.addAll(listA.subList(0, listA.size() / 2)); - expected2.addAll(listC.subList(0, listC.size() / 2)); - assertEqualSet(expected2, instance2); - - ImmutableSet instance3 = instance.addAll(instance2); - assertNotSame(instance2, instance3); - expected.addAll(expected2); - assertEqualSet(expected, instance3); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addAllWithSameTypeAndAllNewKeysShouldReturnNewInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - ImmutableSet instance2 = newInstance(data.c); - ImmutableSet instance3 = instance.addAll(instance2); - assertNotSame(instance2, instance3); - - LinkedHashSet expected = new LinkedHashSet<>(data.a.asSet()); - expected.addAll(data.c.asSet()); - assertEqualSet(expected, instance3); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addAllWithSameTypeToMutableAndAllNewKeysShouldReturnNewInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - ImmutableSet instance2 = newInstance(data.c); - ImmutableSet instance3 = instance.addAll(instance2.toMutable()); - assertNotSame(instance2, instance3); - - LinkedHashSet expected = new LinkedHashSet<>(data.a.asSet()); - expected.addAll(data.c.asSet()); - assertEqualSet(expected, instance3); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void toMutableAddAllWithSameTypeAndAllNewKeysShouldReturnTrue(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - ImmutableSet instance2 = newInstance(data.c); - Set mutableInstance = instance.toMutable(); - assertTrue(mutableInstance.addAll(instance2.asSet())); - - LinkedHashSet expected = new LinkedHashSet<>(data.a.asSet()); - expected.addAll(data.c.asSet()); - assertEqualSet(expected, toImmutableInstance(mutableInstance)); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void toStringShouldContainAllElements(@NonNull SetData data) { - ImmutableSet instance = newInstance(); - assertEquals("[]", instance.toString()); - - instance = instance.addAll(data.a.asSet()); - String str = instance.toString(); - assertEquals('[', str.charAt(0)); - assertEquals(']', str.charAt(str.length() - 1)); - LinkedHashSet actual = new LinkedHashSet<>(Arrays.asList(str.substring(1, str.length() - 1).split(", "))); - Set expected = new LinkedHashSet<>(); - data.a.iterator().forEachRemaining(e -> expected.add(e.toString())); - assertEquals(expected, actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void retainAllWithCloneShouldReturnThis(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - ImmutableSet clone = toClonedInstance(instance); - assertNotSame(instance, clone); - ImmutableSet actual = instance.retainAll(clone); - assertSame(instance, actual); - assertEqualSet(data.a, actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void retainAllWithContainedElementsShouldReturnThis(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - ImmutableSet actual = instance.retainAll(data.a.asSet()); - assertSame(instance, actual); - assertEqualSet(data.a, actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void retainAllWithSomeContainedElementsShouldReturnNewInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - Set expected = new LinkedHashSet<>(data.a.asSet()); - ImmutableSet actual = instance.retainAll(data.someAPlusSomeB.asSet()); - assertNotSame(instance, actual); - assertEqualSet(expected, instance); - assertTrue(expected.retainAll(data.someAPlusSomeB.asSet())); - assertEqualSet(expected, actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void retainAllWithNewElementsShouldReturnNewInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - ImmutableSet instance2 = instance.retainAll(data.c.asSet()); - assertNotSame(instance, instance2); - assertEqualSet(data.a, instance); - assertEqualSet(Collections.emptySet(), instance2); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void retainAllWithSameTypeAndAllNewKeysShouldReturnNewInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - ImmutableSet instance2 = newInstance(data.c); - ImmutableSet instance3 = instance.retainAll(instance2); - assertNotSame(instance, instance3); - assertEqualSet(data.a, instance); - assertEqualSet(data.c, instance2); - assertEqualSet(Collections.emptySet(), instance3); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void retainAllWithSameTypeAndSomeNewKeysShouldReturnNewInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - - ArrayList listA = new ArrayList<>(data.a.asSet()); - ArrayList listC = new ArrayList<>(data.c.asSet()); - - ImmutableSet instance2 = newInstance(); - instance2 = instance2.addAll(listA.subList(0, listA.size() / 2)); - instance2 = instance2.addAll(listC.subList(0, listC.size() / 2)); - - LinkedHashSet expected = new LinkedHashSet<>(listA); - LinkedHashSet expected2 = new LinkedHashSet<>(); - expected2.addAll(listA.subList(0, listA.size() / 2)); - expected2.addAll(listC.subList(0, listC.size() / 2)); - assertEqualSet(expected2, instance2); - - ImmutableSet instance3 = instance.retainAll(instance2); - assertNotSame(instance2, instance3); - expected.retainAll(expected2); - assertEqualSet(expected, instance3); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void retainAllWithSelfShouldReturnThis(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - assertSame(instance, instance.retainAll(instance)); - assertEqualSet(data.a, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void retainAllWithSomeNewKeysShouldReturnNewInstance(org.jhotdraw8.collection.@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - ImmutableSet instance2 = instance.retainAll(data.someAPlusSomeB.asSet()); - assertNotSame(instance, instance2); - LinkedHashSet expected = new LinkedHashSet<>(data.a.asSet()); - assertEqualSet(expected, instance); - expected.retainAll(data.someAPlusSomeB.asSet()); - assertEqualSet(expected, instance2); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void retainAllOfEmptySetShouldReturnThis(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(); - assertSame(instance, instance.retainAll(data.c.asSet())); - assertEqualSet(Collections.emptySet(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void retainAllWithEmptySetShouldReturnNewInstance(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a.asSet()); - ImmutableSet instance2 = instance.retainAll(Collections.emptySet()); - assertNotSame(instance, instance2); - assertEqualSet(Collections.emptySet(), instance2); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractIntSequencedCollectionTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractIntSequencedCollectionTest.java deleted file mode 100755 index 0223d3aa5..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractIntSequencedCollectionTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * @(#)AbstractIntSequencedCollectionTest.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection; - - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.primitive.IntSequencedCollection; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; - -/** - * Tests classes that implement the interface {@link IntSequencedCollection}. - */ - -public abstract class AbstractIntSequencedCollectionTest { - - public AbstractIntSequencedCollectionTest() { - } - - /** - * Test of addFirst method, of class IntSequencedCollection. - */ - @Test - public void testAddFirst() { - int e = 1; - IntSequencedCollection instance = newInstance(); - instance.addFirstAsInt(e); - assertFalse(instance.isEmpty()); - - assertEquals(1, instance.getFirstAsInt()); - - instance.addFirstAsInt(2); - assertEquals(2, instance.getFirstAsInt()); - assertEquals(2, instance.size()); - } - - @NonNull - protected abstract IntSequencedCollection newInstance(); - - /** - * Test of addLast method, of class IntSequencedCollection. - */ - @Test - public void testAddLast() { - int e = 1; - IntSequencedCollection instance = newInstance(); - instance.addLastAsInt(e); - assertFalse(instance.isEmpty()); - - assertEquals(1, instance.getLastAsInt()); - - instance.addLastAsInt(2); - assertEquals(2, instance.getLastAsInt()); - assertEquals(2, instance.size()); - } - - @Test - public void testAddAll() { - IntSequencedCollection instance = newInstance(); - instance.addLastAllAsInt(new int[]{1, 2, 3}); - instance.addLastAllAsInt(new int[]{4, 5}); - instance.addLastAllAsInt(new int[]{0, 6, 7}, 1, 2); - assertEquals(1, instance.removeFirstAsInt()); - assertEquals(2, instance.removeFirstAsInt()); - instance.addLastAllAsInt(new int[]{8, 9}); - instance.addLastAllAsInt(new int[]{10, 11}); - - IntSequencedCollection expected = newInstance(); - expected.addLastAllAsInt(new int[]{3, 4, 5, 6, 7, 8, 9, 10, 11}); - assertEquals(expected, instance); - assertEquals(expected.hashCode(), instance.hashCode()); - - assertEquals(3, instance.removeFirstAsInt()); - assertEquals(4, instance.removeFirstAsInt()); - assertEquals(5, instance.removeFirstAsInt()); - assertEquals(11, instance.removeLastAsInt()); - assertEquals(10, instance.removeLastAsInt()); - instance.addLastAllAsInt(new int[]{10, 11, 12, 13, 14, 15, 16, 17, 18, 19}); - - expected.clear(); - expected.addLastAllAsInt(new int[]{6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}); - assertEquals(expected, instance); - assertEquals(expected.hashCode(), instance.hashCode()); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractListLongRunningTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractListLongRunningTest.java deleted file mode 100644 index 3271aae14..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractListLongRunningTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.jhotdraw8.collection; - -import org.jhotdraw8.collection.computed.ComputedList; -import org.jhotdraw8.collection.readonly.SizeLimitExceededException; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -@Disabled - -public abstract class AbstractListLongRunningTest { - abstract List createInstance(); - - abstract long maxSize(); - - /** - *
    - *
  1. GIVEN a new list instance
  2. - *
  3. WHEN we add {@link #maxSize()} elements
  4. - *
  5. THEN the list must not throw a {@link SizeLimitExceededException}
  6. - *
  7. WHEN we add one element more - *
  8. THEN the list must throw a {@link SizeLimitExceededException}
  9. - *
- * Should not throw a size limit exception, when we add {@link #maxSize()} elements. - */ - @Test - @Disabled - public void shouldThrowSizeLimitExceededException() { - List instance = createInstance(); - ComputedList toBeAdded = new ComputedList<>(maxSize(), i -> 42L); - instance.addAll(toBeAdded.asList()); - assertEquals(maxSize(), instance.size(), "size"); - assertThrows(SizeLimitExceededException.class, () -> instance.add(maxSize() + 1)); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractListTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractListTest.java deleted file mode 100644 index 7b87e1b98..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractListTest.java +++ /dev/null @@ -1,118 +0,0 @@ -package org.jhotdraw8.collection; - -import de.sandec.jmemorybuddy.JMemoryBuddy; -import org.jhotdraw8.annotation.NonNull; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.ConcurrentModificationException; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.NoSuchElementException; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -public abstract class AbstractListTest extends AbstractSequencedCollectionTest { - - - protected abstract @NonNull List newListInstance(); - - @ParameterizedTest - @MethodSource("dataProvider") - public void iteratorShouldThrowNoSuchElementException(@NonNull SetData data) throws Exception { - List l = newListInstance(); - l.add(data.a.iterator().next()); - Iterator i = l.iterator(); - i.next(); - i.remove(); - assertThrows(NoSuchElementException.class, () -> i.next()); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void iteratorShouldThrowConcurrentModificationException(@NonNull SetData data) throws Exception { - List l = newListInstance(); - HashCollider valueA = data.a.iterator().next(); - l.add(valueA); - Iterator i = l.iterator(); - i.next(); - l.remove(valueA); - assertThrows(ConcurrentModificationException.class, () -> i.next()); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void listIteratorShouldThrowNoSuchElementException(@NonNull SetData data) throws Exception { - List l = newListInstance(); - l.add(data.a.iterator().next()); - ListIterator i = l.listIterator(); - i.next(); - i.remove(); - assertThrows(NoSuchElementException.class, () -> i.next()); - } - - - @ParameterizedTest - @MethodSource("dataProvider") - public void listIteratorShouldThrowNoSuchElementException2(@NonNull SetData data) throws Exception { - List l = newListInstance(); - l.add(data.a.iterator().next()); - ListIterator i = l.listIterator(); - i.add(data.b.iterator().next()); - i.next(); - i.remove(); - assertThrows(NoSuchElementException.class, () -> i.next()); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void listIteratorShouldThrowIllegalStateException(@NonNull SetData data) throws Exception { - List l = newListInstance(); - ListIterator i = l.listIterator(); - i.hasNext(); - i.hasNext(); - i.add(data.a.iterator().next()); - assertThrows(IllegalStateException.class, () -> i.remove()); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void listShouldAffectSubList(@NonNull SetData data) throws Exception { - List l = newListInstance(); - l.add(data.a.iterator().next()); - List subList = l.subList(0, 1); - Iterator subIterator = subList.iterator(); - l.set(0, data.b.iterator().next()); - HashCollider actualValue = subIterator.next(); - assertEquals(data.b.iterator().next(), actualValue); - } - - @ParameterizedTest - @MethodSource("dataProvider") - @Disabled("test is flaky") - public void removeOneElementShouldMakeElementCollectable(@NonNull SetData data) throws Exception { - JMemoryBuddy.memoryTest(checker -> { - var a = data.a.stream().map(HashCollider::clone).toList(); - var b = data.b.stream().map(HashCollider::clone).toList(); - ArrayList shuffled = new ArrayList<>(); - shuffled.addAll(a); - shuffled.addAll(b); - Collections.shuffle(shuffled); - - - var instance = newInstance(); - instance.addAll(shuffled); - instance.remove(b.iterator().next()); - - checker.setAsReferenced(instance); - - checker.assertCollectable(b.iterator().next()); // notReferenced should be collectable - }); - } - -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractMapTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractMapTest.java deleted file mode 100644 index 1e61c4496..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractMapTest.java +++ /dev/null @@ -1,649 +0,0 @@ -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.readonly.ReadOnlyMap; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public abstract class AbstractMapTest { - - private static final MapData NO_COLLISION = MapData.newData("no collisions", -1, 32, 100_000); - private static final MapData ALL_COLLISION = MapData.newData("all collisions", 0, 32, 100_000); - private static final MapData SOME_COLLISION = MapData.newData("some collisions", 0x55555555, 32, 100_000); - - public static Stream dataProvider() { - return Stream.of( - NO_COLLISION, ALL_COLLISION, SOME_COLLISION - ); - } - - protected void assertEqualMap(ReadOnlyMap expected, Map actual) { - assertEqualMap(expected.asMap(), actual); - } - - protected void assertEqualMap(Map expected, Map actual) { - assertEquals(expected.size(), actual.size()); - assertEquals(expected.isEmpty(), actual.isEmpty()); - assertEquals(expected.hashCode(), actual.hashCode()); - assertEquals(expected, actual); - assertEquals(actual, expected); - assertEquals(expected.entrySet(), actual.entrySet()); - assertEquals(expected.keySet(), actual.keySet()); - assertEquals(new LinkedHashSet<>(expected.values()), - new LinkedHashSet<>(actual.values())); - } - - protected void assertNotEqualMap(Map expected, Map actual) { - assertNotEquals(expected, actual); - assertNotEquals(actual, expected); - assertNotEquals(expected.entrySet(), actual.entrySet()); - } - - /** - * Creates a new empty instance. - */ - protected abstract @NonNull Map newInstance(); - - /** - * Creates a new instance with the specified expected number of elements - * and load factor. - */ - protected abstract @NonNull Map newInstance(int numElements, float loadFactor); - - /** - * Creates a new instance with the specified map. - */ - protected abstract @NonNull Map newInstance(@NonNull Map m); - - /** - * Creates a new instance with the specified map. - */ - abstract @NonNull Map newInstance(@NonNull Iterable> m); - - @ParameterizedTest - @MethodSource("dataProvider") - public void clearShouldBeIdempotent(@NonNull MapData data) { - Map instance = newInstance(data.a()); - assertNotEqualMap(Collections.emptyMap(), instance); - instance.clear(); - assertEqualMap(Collections.emptyMap(), instance); - instance.clear(); - assertEqualMap(Collections.emptyMap(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void clearShouldYieldEmptyMap(@NonNull MapData data) { - Map instance = newInstance(data.a()); - assertNotEqualMap(Collections.emptyMap(), instance); - instance.clear(); - assertEqualMap(Collections.emptyMap(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void cloneShouldYieldEqualMap(@NonNull MapData data) { - Map instance = newInstance(data.a()); - Map clone = toClonedInstance(instance); - assertEqualMap(data.a(), clone); - } - - @SuppressWarnings("SuspiciousMethodCalls") - @ParameterizedTest - @MethodSource("dataProvider") - public void containsKeyShouldYieldExpectedValue(@NonNull MapData data) { - Map instance = newInstance(data.a()); - for (HashCollider k : data.a().readOnlyKeySet()) { - assertTrue(instance.containsKey(k)); - } - for (HashCollider k : data.c().readOnlyKeySet()) { - assertFalse(instance.containsKey(k)); - } - assertFalse(instance.containsKey(new Object())); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void entryIteratorEntrySetValueShouldUpdateMap(@NonNull MapData data) { - Map instance = newInstance(data.a()); - Map expected = new LinkedHashMap<>(data.a().asMap()); - for (Map.Entry entry : instance.entrySet()) { - entry.setValue(data.aWithDifferentValues().get(entry.getKey())); - assertNotEqualMap(instance, expected); - expected.put(entry.getKey(), data.aWithDifferentValues().get(entry.getKey())); - assertEqualMap(instance, expected); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void entryIteratorRemoveShouldRemoveEntryAndRemoveIsNotIdempotent(@NonNull MapData data) { - Map instance = newInstance(data.a()); - Map expected = new LinkedHashMap<>(data.a().asMap()); - List> toRemove = new ArrayList<>(new HashSet<>(data.a().readOnlyEntrySet().asSet())); - for (int countdown = toRemove.size(); countdown > 0; countdown--) { - for (Iterator> i = instance.entrySet().iterator(); i.hasNext(); ) { - Map.Entry k = i.next(); - if (k.equals(toRemove.get(0))) { - i.remove(); - toRemove.remove(0); - expected.remove(k.getKey()); - assertEqualMap(expected, instance); - - assertThrows(IllegalStateException.class, i::remove); - } - } - } - assertEqualMap(Collections.emptyMap(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void entryIteratorShouldYieldExpectedEntries(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a); - List> actualList = new ArrayList<>(); - LinkedHashMap actualMap = new LinkedHashMap<>(); - instance.entrySet().iterator().forEachRemaining(actualList::add); - instance.entrySet().iterator().forEachRemaining(e -> actualMap.put(e.getKey(), e.getValue())); - assertEquals(data.a.size(), actualList.size()); - assertEqualMap(data.a, actualMap); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void entrySetContainsExpectedEntries(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a); - Set> entrySet = instance.entrySet(); - for (Map.Entry e : data.a) { - assertTrue(entrySet.contains(e)); - } - for (Map.Entry e : data.aWithDifferentValues) { - assertFalse(entrySet.contains(e)); - } - for (Map.Entry e : data.c) { - assertFalse(entrySet.contains(e)); - } - assertTrue(entrySet.containsAll(data.a.readOnlyEntrySet().asSet())); - assertFalse(entrySet.containsAll(data.aWithDifferentValues.readOnlyEntrySet().asSet())); - assertFalse(entrySet.containsAll(data.c.readOnlyEntrySet().asSet())); - LinkedHashSet> abc = new LinkedHashSet<>(data.a.readOnlyEntrySet().asSet()); - abc.addAll(data.aWithDifferentValues.readOnlyEntrySet().asSet()); - abc.addAll(data.c.readOnlyEntrySet().asSet()); - assertFalse(entrySet.containsAll(abc)); - } - - @SuppressWarnings("SuspiciousMethodCalls") - @ParameterizedTest - @MethodSource("dataProvider") - public void entrySetContainsShouldYieldExpectedValue(@NonNull MapData data) { - Map instance = newInstance(data.a()); - for (Map.Entry e : data.a().readOnlyEntrySet()) { - assertTrue(instance.entrySet().contains(e)); - } - for (Map.Entry e : data.aWithDifferentValues().readOnlyEntrySet()) { - assertFalse(instance.entrySet().contains(e)); - } - for (Map.Entry e : data.c().readOnlyEntrySet()) { - assertFalse(instance.entrySet().contains(e)); - } - assertFalse(instance.entrySet().contains(new Object())); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void entrySetRemoveAllWithContainedEntryShouldReturnTrue(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a); - assertTrue(instance.entrySet().removeAll(data.a.readOnlyEntrySet().asSet())); - assertEqualMap(Collections.emptyMap(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void entrySetRemoveAllWithEntriesThatHaveSameKeyButDifferentValueShouldReturnFalse(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a); - assertFalse(instance.entrySet().removeAll(data.aWithDifferentValues.readOnlyEntrySet().asSet())); - assertEqualMap(data.a, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void entrySetRemoveAllWithNewEntryShouldReturnFalse(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a); - assertFalse(instance.entrySet().removeAll(data.c.readOnlyEntrySet().asSet())); - assertEqualMap(data.a, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void entrySetRemoveShouldNotRemoveEntryWithDifferentKeyAndDifferentValue(@NonNull MapData data) { - Map instance = newInstance(data.a()); - Map expected = new LinkedHashMap<>(data.a().asMap()); - for (Map.Entry e : data.c().readOnlyEntrySet()) { - assertFalse(instance.entrySet().remove(e)); - assertEqualMap(expected, instance); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void entrySetRemoveShouldNotRemoveEntryWithSameKeyButDifferentValue(@NonNull MapData data) { - Map instance = newInstance(data.a()); - Map expected = new LinkedHashMap<>(data.a().asMap()); - for (Map.Entry e : data.aWithDifferentValues().readOnlyEntrySet()) { - assertFalse(instance.entrySet().remove(e)); - assertEqualMap(expected, instance); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void entrySetRemoveShouldRemoveEntryWithSameKeyAndValue(@NonNull MapData data) { - Map instance = newInstance(data.a()); - Map expected = new LinkedHashMap<>(data.a().asMap()); - - for (Map.Entry e : data.a().readOnlyEntrySet()) { - assertTrue(instance.entrySet().remove(e)); - expected.entrySet().remove(e); - assertEqualMap(expected, instance); - } - assertEqualMap(Collections.emptyMap(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void equalWithThisShouldYieldTrue(@NonNull MapData data) { - Map instance = newInstance(data.a()); - assertEquals(instance, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void equalsWithCloneWithUpdatedEntriesShouldYieldFalse(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a()); - Map instance2 = toClonedInstance(instance); - assertEquals(instance, instance2); - instance2.putAll(data.aWithDifferentValues().asMap()); - assertNotEquals(instance, instance2); - } - - @SuppressWarnings("SimplifiableAssertion") - @ParameterizedTest - @MethodSource("dataProvider") - public void equalsWithNullShouldYieldFalse(@NonNull MapData data) { - Map instance = newInstance(data.a()); - assertFalse(instance.equals(null)); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void equalsWithObjectShouldYieldFalse(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a()); - assertNotEquals(instance, new Object()); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void getOrDefaultWithContainedKeyShouldYieldValue(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a()); - HashCollider defaultValue = new HashCollider(7, -1); - for (Map.Entry e : data.a()) { - assertEquals(e.getValue(), instance.getOrDefault(e.getKey(), defaultValue)); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void getOfEntryWithNullValueShouldYieldNull(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a()); - LinkedHashMap expected = new LinkedHashMap<>(data.a.asMap()); - HashCollider key = new HashCollider(42, -1); - assertNull(instance.put(key, null)); - expected.put(key, null); - assertTrue(instance.containsKey(key)); - assertNull(instance.get(key)); - assertEqualMap(expected, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void getOrDefaultWithNonContainedKeyShouldYieldDefault(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a()); - HashCollider defaultValue = new HashCollider(7, -1); - for (Map.Entry e : data.c()) { - assertEquals(defaultValue, instance.getOrDefault(e.getKey(), defaultValue)); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void iteratorRemoveShouldThrowIllegalStateException(@NonNull MapData data) { - Map instance = newInstance(data.a()); - Iterator i = instance.keySet().iterator(); - assertThrows(IllegalStateException.class, i::remove); - Iterator k = instance.values().iterator(); - assertThrows(IllegalStateException.class, k::remove); - Iterator> j = instance.entrySet().iterator(); - assertThrows(IllegalStateException.class, j::remove); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void keyIteratorRemoveShouldRemoveEntry(@NonNull MapData data) { - Map instance = newInstance(data.a()); - Map expected = new LinkedHashMap<>(data.a().asMap()); - List toRemove = new ArrayList<>(new HashSet<>(data.a().readOnlyKeySet().asSet())); - while (!toRemove.isEmpty() && !expected.isEmpty()) { - for (Iterator i = instance.keySet().iterator(); i.hasNext(); ) { - HashCollider k = i.next(); - if (k.equals(toRemove.get(0))) { - i.remove(); - toRemove.remove(0); - expected.remove(k); - assertEqualMap(expected, instance); - } - } - } - assertEqualMap(Collections.emptyMap(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void keySetRemoveAllOfEmptyMapShouldReturnFalse(@NonNull MapData data) throws Exception { - Map instance = newInstance(); - assertFalse(instance.keySet().removeAll(data.a.readOnlyKeySet().asSet())); - assertEqualMap(Collections.emptyMap(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void keySetRemoveAllWithEmptyMapShouldReturnFalse(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a); - assertFalse(instance.keySet().removeAll(Collections.emptySet())); - assertEqualMap(data.a(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void keySetRemoveAllWithContainedKeyShouldReturnTrue(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a); - assertTrue(instance.keySet().removeAll(data.a.readOnlyKeySet().asSet())); - assertEqualMap(Collections.emptyMap(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void keySetRemoveAllWithSomeContainedKeyShouldReturnTrue(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a); - assertTrue(instance.keySet().removeAll(data.someAPlusSomeB().readOnlyKeySet().asSet())); - LinkedHashMap expected = new LinkedHashMap<>(data.a.asMap()); - expected.keySet().removeAll(data.someAPlusSomeB().readOnlyKeySet().asSet()); - assertEqualMap(expected, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void keySetRemoveAllWithNewKeyShouldReturnFalse(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a); - assertFalse(instance.keySet().removeAll(data.c.readOnlyKeySet().asSet())); - assertEqualMap(data.a, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void keySetRetainAllOfEmptyMapShouldNotChangeMap(@NonNull MapData data) throws Exception { - Map instance = newInstance(); - instance.keySet().retainAll(data.a().asMap().keySet()); - assertEqualMap(Collections.emptyMap(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void keySetRetainAllWithContainedKeysShouldNotChangeMap(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a()); - instance.keySet().retainAll(data.a().asMap().keySet()); - assertEqualMap(data.a().asMap(), instance); - } - - @SuppressWarnings("SuspiciousMethodCalls") - @ParameterizedTest - @MethodSource("dataProvider") - public void keySetRetainAllWithEmptySetShouldClearMap(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a()); - instance.keySet().retainAll(Collections.emptySet()); - assertEqualMap(Collections.emptyMap(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void keySetRetainAllWithSomeContainedKeysShouldChangeMap(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a()); - LinkedHashMap expected = new LinkedHashMap<>(data.a.asMap()); - instance.keySet().retainAll(data.someAPlusSomeB().asMap().keySet()); - expected.keySet().retainAll(data.someAPlusSomeB().asMap().keySet()); - assertEqualMap(expected, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void keySetRetainAllWithSomeContainedKeysShouldReturnNewInstance(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a()); - assertTrue(instance.keySet().retainAll(data.someAPlusSomeB().asMap().keySet())); - LinkedHashMap expected = new LinkedHashMap<>(data.a().asMap()); - expected.keySet().retainAll(data.someAPlusSomeB().asMap().keySet()); - assertEqualMap(expected, instance); - } - - @Test - public void newInstanceCapacityArgsShouldBeEmpty() { - Map actual = newInstance(24, 0.75f); - LinkedHashMap expected = new LinkedHashMap<>(24, 0.75f); - assertEqualMap(expected, actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void newInstanceIterableArgShouldBeEqualToArg(@NonNull MapData data) { - Map actual = newInstance(data.a().readOnlyEntrySet()); - assertEqualMap(data.a(), actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void newInstanceMapArgsOfSameTypeShouldBeEqualToArg(@NonNull MapData data) { - Map actual1 = newInstance(data.a().asMap()); - Map actual = newInstance(actual1); - assertEqualMap(data.a(), actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void newInstanceMapArgsShouldBeEqualToArg(@NonNull MapData data) { - Map actual = newInstance(data.a().asMap()); - assertEqualMap(data.a(), actual); - } - - @Test - public void newInstanceNoArgsShouldBeEmpty() { - Map actual = newInstance(); - LinkedHashMap expected = new LinkedHashMap<>(); - assertEqualMap(expected, actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void newInstanceReadOnlyMapArgShouldBeEqualToARg(@NonNull MapData data) { - Map actual = newInstance(data.a()); - assertEqualMap(data.a(), actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void putAllWithContainedEntriesShouldNotChangeMap(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a()); - instance.putAll(data.a().asMap()); - assertEqualMap(data.a().asMap(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void putAllWithContainedKeysButNewValuesShouldChangeMap(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a()); - instance.putAll(data.aWithDifferentValues().asMap()); - Map expected = new LinkedHashMap<>(data.a().asMap()); - expected.putAll(data.aWithDifferentValues().asMap()); - assertEqualMap(expected, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void putAllWithNewEntriesShouldChangeMap(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a()); - instance.putAll(data.c().asMap()); - Map expected = new LinkedHashMap<>(data.a().asMap()); - expected.putAll(data.c().asMap()); - assertEqualMap(expected, instance); - } - - @SuppressWarnings({"CollectionAddedToSelf"}) - @ParameterizedTest - @MethodSource("dataProvider") - public void putAllWithSelfShouldYieldSameMap(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a()); - instance.putAll(instance); - assertEqualMap(data.a(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void putAllWithSomeNewKeyShouldAddAll(@NonNull MapData data) throws Exception { - ArrayList> listB = new ArrayList<>(data.aWithDifferentValues.readOnlyEntrySet().asSet()); - ArrayList> listC = new ArrayList<>(data.c.readOnlyEntrySet().asSet()); - Map m = new LinkedHashMap<>(data.a.asMap()); - for (Map.Entry entry : listB.subList(0, listB.size() / 2)) { - m.put(entry.getKey(), entry.getValue()); - } - for (Map.Entry entry : listC.subList(0, listC.size() / 2)) { - m.put(entry.getKey(), entry.getValue()); - } - Map instance = newInstance(data.a); - instance.putAll(m); - LinkedHashMap expected = new LinkedHashMap<>(data.a.asMap()); - expected.putAll(m); - assertEqualMap(expected, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void putWithContainedEntryShouldReturnOldValue(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a()); - LinkedHashMap expected = new LinkedHashMap<>(data.a().asMap()); - for (Map.Entry e : data.aWithDifferentValues) { - assertEquals(expected.get(e.getKey()), instance.put(e.getKey(), e.getValue())); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void putWithContainedKeyButNewValueShouldReturnOldValue(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a()); - LinkedHashMap expected = new LinkedHashMap<>(data.a().asMap()); - for (Map.Entry e : data.aWithDifferentValues) { - assertEquals(expected.get(e.getKey()), instance.put(e.getKey(), e.getValue())); - expected.put(e.getKey(), e.getValue()); - assertEqualMap(expected, instance); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void putWithNewKeyShouldReturnNull(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a); - for (Map.Entry e : data.c) { - assertNull(instance.put(e.getKey(), e.getValue())); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeWithContainedKeyShouldReturnOldValue(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a); - LinkedHashMap expected = new LinkedHashMap<>(data.a().asMap()); - for (Map.Entry e : data.aWithDifferentValues) { - HashCollider expectedRemoved = expected.remove(e.getKey()); - assertEquals(expectedRemoved, instance.remove(e.getKey())); - assertEqualMap(expected, instance); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeWithNewKeyShouldReturnNull(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a); - for (Map.Entry e : data.c) { - assertNull(instance.remove(e.getKey())); - assertEqualMap(data.a.asMap(), instance); - } - } - - @SuppressWarnings("unchecked") - @ParameterizedTest - @MethodSource("dataProvider") - public void serializationShouldYieldSameMap(@NonNull MapData data) throws Exception { - Map instance = newInstance(data.a()); - assertEqualMap(data.a(), instance); - if (instance instanceof Serializable) { - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - try (ObjectOutputStream out = new ObjectOutputStream(buf)) { - out.writeObject(instance); - } - Map deserialized; - try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buf.toByteArray()))) { - deserialized = (Map) in.readObject(); - } - assertEqualMap(data.a(), deserialized); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void toStringShouldContainAllEntries(@NonNull MapData data) { - Map instance = newInstance(); - assertEquals("{}", instance.toString()); - - instance.putAll(data.a.asMap()); - String str = instance.toString(); - assertEquals('{', str.charAt(0)); - assertEquals('}', str.charAt(str.length() - 1)); - LinkedHashSet actual = new LinkedHashSet<>(Arrays.asList(str.substring(1, str.length() - 1).split(", "))); - Set expected = new LinkedHashSet<>(); - data.a.iterator().forEachRemaining(e -> expected.add(e.toString())); - assertEquals(expected, actual); - } - - protected abstract @NonNull Map toClonedInstance(@NonNull Map m); -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractReadOnlyListTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractReadOnlyListTest.java deleted file mode 100644 index d8a7b04d1..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractReadOnlyListTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.readonly.ReadOnlyList; - -import java.util.List; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public abstract class AbstractReadOnlyListTest { - protected void assertEqualList(@NonNull List expected, @NonNull ReadOnlyList actual) { - Object[] expectedValues = expected.toArray(); - Object[] actualValues = actual.toArray(); - assertArrayEquals(expectedValues, actualValues); - - for (var e : expected) { - assertTrue(actual.contains(e), "must contain " + e); - } - - assertEquals(expected.size(), actual.size()); - assertEquals(expected.isEmpty(), actual.isEmpty()); - assertEquals(expected.hashCode(), actual.hashCode()); - assertEquals(expected, actual.asList()); - assertEquals(actual.asList(), expected); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractReadOnlyMapTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractReadOnlyMapTest.java deleted file mode 100644 index 546df9cd7..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractReadOnlyMapTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.jhotdraw8.collection; - -import org.jhotdraw8.collection.readonly.ReadOnlyMap; - -import java.util.LinkedHashSet; -import java.util.Map; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public abstract class AbstractReadOnlyMapTest { - protected void assertEqualMap(Map expected, ReadOnlyMap actual) { - assertEquals(new LinkedHashSet<>(expected.values()), - new LinkedHashSet<>(actual.readOnlyValues().asCollection())); - assertEquals(expected.size(), actual.size()); - assertEquals(expected.isEmpty(), actual.isEmpty()); - assertEquals(expected.hashCode(), actual.hashCode()); - assertEquals(expected, actual.asMap()); - assertEquals(actual.asMap(), expected); - assertEquals(expected.entrySet(), actual.readOnlyEntrySet().asSet()); - assertEquals(expected.keySet(), actual.readOnlyKeySet().asSet()); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractReadOnlySetTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractReadOnlySetTest.java deleted file mode 100644 index a35711d93..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractReadOnlySetTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.readonly.ReadOnlySet; - -import java.util.LinkedHashSet; -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public abstract class AbstractReadOnlySetTest { - protected void assertEqualSet(@NonNull Set expected, @NonNull ReadOnlySet actual) { - Set expectedValues = new LinkedHashSet<>(expected); - Set actualValues = new LinkedHashSet<>(actual.asSet()); - assertEquals(expectedValues, actualValues); - - for (var e : expected) { - assertTrue(actual.contains(e), "must contain " + e); - } - - assertEquals(expected.size(), actual.size()); - assertEquals(expected.isEmpty(), actual.isEmpty()); - assertEquals(expected.hashCode(), actual.hashCode()); - assertEquals(expected, actual.asSet()); - assertEquals(actual.asSet(), expected); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractSequencedCollectionTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractSequencedCollectionTest.java deleted file mode 100755 index fce24292b..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractSequencedCollectionTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * @(#)AbstractIntSequencedCollectionTest.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection; - - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.sequenced.SequencedCollection; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * Tests classes that implement the interface {@link SequencedCollection}. - */ - -public abstract class AbstractSequencedCollectionTest { - private static final SetData NO_COLLISION_NICE_KEYS = SetData.newNiceData("no collisions nice keys", -1, 32, 100_000); - private static final SetData NO_COLLISION = SetData.newData("no collisions", -1, 32, 100_000); - private static final SetData ALL_COLLISION = SetData.newData("all collisions", 0, 32, 100_000); - private static final SetData SOME_COLLISION = SetData.newData("some collisions", 0x55555555, 32, 100_000); - - public static @NonNull Stream dataProvider() { - return Stream.of( - NO_COLLISION_NICE_KEYS, NO_COLLISION, ALL_COLLISION, SOME_COLLISION - ); - } - - public AbstractSequencedCollectionTest() { - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void shouldAddFirst(@NonNull SetData data) throws Exception { - SequencedCollection instance = newInstance(); - instance.addAll(data.b.asCollection()); - instance.addFirst(data.a.iterator().next()); - - List expected = new ArrayList<>(); - expected.addAll(data.b.asCollection()); - expected.add(0, data.a.iterator().next()); - - assertEquals(expected, instance); - } - - @NonNull - protected abstract SequencedCollection newInstance(); - - @ParameterizedTest - @MethodSource("dataProvider") - public void shouldAddLast(@NonNull SetData data) throws Exception { - SequencedCollection instance = newInstance(); - instance.addAll(data.b.asCollection()); - instance.addLast(data.a.iterator().next()); - - List expected = new ArrayList<>(); - expected.addAll(data.b.asCollection()); - expected.add(data.a.iterator().next()); - - assertEquals(expected, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void shouldAddAll(@NonNull SetData data) throws Exception { - SequencedCollection instance = newInstance(); - instance.addAll(data.a.asCollection()); - instance.addAll(data.b.asCollection()); - instance.addAll(data.c.asCollection()); - - List expected = new ArrayList<>(); - expected.addAll(data.a.asCollection()); - expected.addAll(data.b.asCollection()); - expected.addAll(data.c.asCollection()); - - assertEquals(expected, instance); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractSequencedMapTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractSequencedMapTest.java deleted file mode 100644 index c22b7c7e0..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractSequencedMapTest.java +++ /dev/null @@ -1,251 +0,0 @@ -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableSequencedMap; -import org.jhotdraw8.collection.sequenced.SequencedMap; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; - -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -public abstract class AbstractSequencedMapTest extends AbstractMapTest { - /** - * Creates a new empty instance. - */ - protected abstract @NonNull SequencedMap newInstance(); - - /** - * Creates a new instance with the specified expected number of elements - * and load factor. - */ - protected abstract @NonNull SequencedMap newInstance(int numElements, float loadFactor); - - /** - * Creates a new instance with the specified map. - */ - protected abstract @NonNull SequencedMap newInstance(@NonNull Map m); - - - protected abstract @NonNull ImmutableSequencedMap toImmutableInstance(@NonNull Map m); - - protected abstract @NonNull SequencedMap toClonedInstance(@NonNull Map m); - - protected abstract @NonNull SequencedMap newInstance(@NonNull Iterable> m); - - - @ParameterizedTest - @MethodSource("dataProvider") - public void putFirstWithContainedEntryShouldMoveEntryToFirst(MapData data) throws Exception { - SequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - for (Map.Entry e : data.a()) { - instance.putFirst(e.getKey(), e.getValue()); - assertEquals(e, instance.firstEntry()); - expected.remove(e); - expected.add(0, e); - assertEqualSequence(expected, instance, "putFirst"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void putFirstWithNewElementShouldMoveElementToFirst(MapData data) throws Exception { - SequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - for (Map.Entry e : data.c()) { - instance.putFirst(e.getKey(), e.getValue()); - Map.Entry firstEntry = instance.firstEntry(); - assertEquals(e, firstEntry); - assertNotNull(firstEntry); - assertEquals(e.getKey(), firstEntry.getKey()); - expected.remove(e); - expected.add(0, e); - assertEqualSequence(expected, instance, "putFirst"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void putLastWithContainedElementShouldMoveElementToLast(MapData data) throws Exception { - SequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - for (Map.Entry e : data.a()) { - instance.putLast(e.getKey(), e.getValue()); - Map.Entry lastEntry = instance.lastEntry(); - assertEquals(e, lastEntry); - assertNotNull(lastEntry); - assertEquals(e.getKey(), lastEntry.getKey()); - expected.remove(e); - expected.add(e); - assertEqualSequence(expected, instance, "putLast"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void putLastWithNewElementShouldMoveElementToLast(MapData data) throws Exception { - SequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - for (Map.Entry e : data.c()) { - instance.putLast(e.getKey(), e.getValue()); - assertEquals(e, instance.lastEntry()); - expected.remove(e); - expected.add(e); - assertEqualSequence(expected, instance, "putLast"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void putWithContainedElementShouldNotMoveElementToLast(MapData data) throws Exception { - SequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - for (Map.Entry e : data.a()) { - instance.put(e.getKey(), e.getValue()); - assertEquals(expected.get(expected.size() - 1), instance.lastEntry()); - assertEqualSequence(expected, instance, "put"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeWithLastElementShouldNotChangeSequence(MapData data) throws Exception { - SequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - while (!expected.isEmpty()) { - Map.Entry e = expected.remove(expected.size() - 1); - assertEquals(e.getValue(), instance.remove(e.getKey())); - assertEqualSequence(expected, instance, "remove(lastElement)"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void pollFirstShouldNotChangeSequence(MapData data) throws Exception { - SequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - while (!expected.isEmpty()) { - Map.Entry e = expected.remove(0); - assertEquals(instance.pollFirstEntry(), e); - assertEqualSequence(expected, instance, "pollFirstEntry"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeFirstWithEmptySetShouldReturnNull(MapData data) throws Exception { - SequencedMap instance = newInstance(data.a()); - for (Map.Entry e : data.a()) { - instance.remove(e.getKey()); - } - assertNull(instance.pollFirstEntry()); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void pollLastWithEmptySetShouldReturnNull(MapData data) throws Exception { - SequencedMap instance = newInstance(data.a()); - for (Map.Entry e : data.a()) { - instance.remove(e.getKey()); - } - assertNull(instance.pollLastEntry()); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeLastShouldNotChangeSequence(MapData data) throws Exception { - SequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - while (!expected.isEmpty()) { - assertEquals(instance.pollLastEntry(), expected.remove(expected.size() - 1)); - assertEqualSequence(expected, instance, "pollLastEntry"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeWithFirstElementShouldNotChangeSequence(MapData data) throws Exception { - SequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - while (!expected.isEmpty()) { - Map.Entry e = expected.remove(0); - assertEquals(e.getValue(), instance.remove(e.getKey())); - assertEqualSequence(expected, instance, "remove(firstElement)"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeWithMiddleElementShouldNotChangeSequence(MapData data) throws Exception { - SequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - while (!expected.isEmpty()) { - Map.Entry e = expected.remove(expected.size() / 2); - assertEquals(e.getValue(), instance.remove(e.getKey())); - assertEqualSequence(expected, instance, "removeMiddle"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void putWithNewElementShouldMoveElementToLast(MapData data) throws Exception { - SequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - for (Map.Entry e : data.c()) { - instance.put(e.getKey(), e.getValue()); - assertEquals(e, instance.lastEntry()); - expected.remove(e); - expected.add(e); - assertEqualSequence(expected, instance, "add"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void putNewValueForExistingElementShouldNotChangeSequence(MapData data) throws Exception { - SequencedMap instance = newInstance(data.a()); - List> expected = new ArrayList<>(data.a().asMap().entrySet()); - ArrayList indices = new ArrayList<>(data.a().size()); - for (int i = 0; i < data.a().size(); i++) { - indices.add(i); - } - Collections.shuffle(indices); - for (int i : indices) { - HashCollider newValue = new HashCollider(i, -1); - Map.Entry oldEntry = expected.get(i); - var newEntry = (AbstractMap.SimpleImmutableEntry) new AbstractMap.SimpleImmutableEntry<>(oldEntry.getKey(), newValue); - - instance.put(oldEntry.getKey(), newValue); - expected.set(i, newEntry); - assertEqualSequence(expected, instance, "put " + i + " oldValue: " + oldEntry + " newValue: " + newEntry); - } - } - - protected void assertEqualSequence(Collection> expected, SequencedMap actual, String message) { - ArrayList> expectedList = new ArrayList<>(expected); - assertEquals(expectedList, new ArrayList<>(actual._sequencedEntrySet()), message); - - if (!expected.isEmpty()) { - assertEquals(expectedList.get(0), actual.firstEntry(), message); - assertEquals(expectedList.get(0), actual._sequencedEntrySet().iterator().next(), message); - assertEquals(expectedList.get(expectedList.size() - 1), actual.lastEntry(), message); - assertEquals(expectedList.get(expectedList.size() - 1), actual._reversed()._sequencedEntrySet().iterator().next(), message); - } - - LinkedHashMap x = new LinkedHashMap<>(); - for (Map.Entry e : expected) { - x.put(e.getKey(), e.getValue()); - } - assertEquals(x.toString(), actual.toString(), message); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractSequencedSetTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractSequencedSetTest.java deleted file mode 100644 index cfeeb5e70..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractSequencedSetTest.java +++ /dev/null @@ -1,451 +0,0 @@ -package org.jhotdraw8.collection; - - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableSequencedSet; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedSet; -import org.jhotdraw8.collection.readonly.ReadOnlySet; -import org.jhotdraw8.collection.sequenced.SequencedSet; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.Random; -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public abstract class AbstractSequencedSetTest extends AbstractSetTest { - protected abstract @NonNull SequencedSet newInstance(); - - /** - * Creates a new instance with the specified expected number of elements - * and load factor. - */ - protected abstract @NonNull SequencedSet newInstance(int numElements, float loadFactor); - - /** - * Creates a new instance with the specified map. - */ - protected abstract @NonNull SequencedSet newInstance(@NonNull SequencedSet m); - - protected abstract @NonNull SequencedSet newInstance(@NonNull ReadOnlySequencedSet m); - - protected abstract @NonNull ImmutableSequencedSet toImmutableInstance(@NonNull SequencedSet m); - - protected abstract @NonNull SequencedSet toClonedInstance(@NonNull SequencedSet m); - - - /** - * Creates a new instance with the specified map. - */ - protected abstract @NonNull SequencedSet newInstance(Set m); - - protected abstract @NonNull SequencedSet newInstance(ReadOnlySet m); - - protected abstract @NonNull ImmutableSequencedSet toImmutableInstance(Set m); - - protected abstract @NonNull SequencedSet toClonedInstance(Set m); - - /** - * Creates a new instance with the specified map. - */ - protected abstract @NonNull SequencedSet newInstance(Iterable m); - - @ParameterizedTest - @MethodSource("dataProvider") - public void addFirstWithContainedElementShouldMoveElementToFirst(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - ArrayList shuffled = new ArrayList<>(data.a().asSet()); - Collections.shuffle(shuffled, new Random(0)); - for (HashCollider e : shuffled) { - instance.addFirst(e); - assertEquals(e, instance.getFirst()); - assertEquals(e, instance._reversed().getLast()); - assertEquals(e, instance._reversed()._reversed().getFirst()); - expected.remove(e); - expected.add(0, e); - assertEqualSequence(expected, instance, "addFirst"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void reversedAddLastWithContainedElementShouldMoveElementToFirst(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - ArrayList shuffled = new ArrayList<>(data.a().asSet()); - Collections.shuffle(shuffled, new Random(0)); - for (HashCollider e : shuffled) { - instance._reversed().addLast(e); - assertEquals(e, instance.getFirst()); - assertEquals(e, instance._reversed().getLast()); - assertEquals(e, instance._reversed()._reversed().getFirst()); - expected.remove(e); - expected.add(0, e); - assertEqualSequence(expected, instance, "addFirst"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addFirstWithNewElementShouldMoveElementToFirst(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - for (HashCollider e : data.c()) { - assertFalse(instance.contains(e)); - assertFalse(instance._reversed().contains(e)); - instance.addFirst(e); - assertEquals(e, instance.getFirst()); - assertEquals(e, instance._reversed().getLast()); - assertEquals(e, instance._reversed()._reversed().getFirst()); - expected.remove(e); - expected.add(0, e); - assertEqualSequence(expected, instance, "addFirst"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void reversedAddLastWithNewElementShouldMoveElementToFirst(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - for (HashCollider e : data.c()) { - assertFalse(instance.contains(e)); - assertFalse(instance._reversed().contains(e)); - instance._reversed().addLast(e); - assertEquals(e, instance.getFirst()); - assertEquals(e, instance._reversed().getLast()); - assertEquals(e, instance._reversed()._reversed().getFirst()); - expected.remove(e); - expected.add(0, e); - assertEqualSequence(expected, instance, "addFirst"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addLastWithContainedElementShouldMoveElementToLast(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - ArrayList shuffled = new ArrayList<>(data.a().asSet()); - Collections.shuffle(shuffled, new Random(0)); - for (HashCollider e : shuffled) { - instance.addLast(e); - assertEquals(e, instance.getLast()); - assertEquals(e, instance._reversed().getFirst()); - assertEquals(e, instance._reversed()._reversed().getLast()); - expected.remove(e); - expected.add(e); - assertEqualSequence(expected, instance, "addLast"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addLastWithLastElementShouldBeIdempotent(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - HashCollider e = expected.get(expected.size() - 1); - instance.addLast(e); - assertEqualSequence(expected, instance, "addLastIdempotent"); - - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addFirstWithFirstElementShouldBeIdempotent(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - HashCollider e = expected.get(0); - instance.addFirst(e); - assertEqualSequence(expected, instance, "addFirstIdempotent"); - - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void reversedAddFirstWithContainedElementShouldMoveElementToLast(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - ArrayList shuffled = new ArrayList<>(data.a().asSet()); - Collections.shuffle(shuffled, new Random(0)); - for (HashCollider e : shuffled) { - instance._reversed().addFirst(e); - assertEquals(e, instance.getLast()); - assertEquals(e, instance._reversed().getFirst()); - assertEquals(e, instance._reversed()._reversed().getLast()); - expected.remove(e); - expected.add(e); - assertEqualSequence(expected, instance, "addLast"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addLastWithNewElementShouldMoveElementToLast(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - for (HashCollider e : data.c()) { - instance.addLast(e); - assertEquals(e, instance.getLast()); - expected.remove(e); - expected.add(e); - assertEqualSequence(expected, instance, "addLast"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void reversedAddFirstWithNewElementShouldMoveElementToLast(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - for (HashCollider e : data.c()) { - instance._reversed().addFirst(e); - assertEquals(e, instance.getLast()); - expected.remove(e); - expected.add(e); - assertEqualSequence(expected, instance, "addLast"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addWithContainedElementShouldNotMoveElementToLast(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - ArrayList shuffled = new ArrayList<>(data.a().asSet()); - Collections.shuffle(shuffled, new Random(0)); - for (HashCollider e : shuffled) { - instance.add(e); - assertEquals(expected.get(expected.size() - 1), instance.getLast()); - assertEqualSequence(expected, instance, "add"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeWithLastElementShouldNotChangeSequence(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - while (!expected.isEmpty()) { - assertTrue(instance.remove(expected.remove(expected.size() - 1))); - assertEqualSequence(expected, instance, "remove(lastElement)"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeFirstShouldNotChangeSequence(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - while (!expected.isEmpty()) { - assertEquals(instance.removeFirst(), expected.remove(0)); - assertEqualSequence(expected, instance, "removeFirst"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void reversedRemoveLastShouldNotChangeSequence(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - while (!expected.isEmpty()) { - assertEquals(instance._reversed().removeLast(), expected.remove(0)); - assertEqualSequence(expected, instance, "removeFirst"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeFirstWithEmptySetShouldThrowNoSuchElementException(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - instance.removeAll(data.a().asSet()); - assertThrows(NoSuchElementException.class, instance::removeFirst); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeLastWithEmptySetShouldThrowNoSuchElementException(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - instance.removeAll(data.a().asSet()); - assertThrows(NoSuchElementException.class, instance::removeLast); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeLastShouldNotChangeSequence(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - while (!expected.isEmpty()) { - assertEquals(instance.removeLast(), expected.remove(expected.size() - 1)); - assertEqualSequence(expected, instance, "removeLast"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeLastStartingWithEmptySetShouldNotChangeSequence(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(); - instance.addAll(data.a.asSet()); - List expected = new ArrayList<>(data.a().asSet()); - while (!expected.isEmpty()) { - assertEquals(instance.removeLast(), expected.remove(expected.size() - 1)); - assertEqualSequence(expected, instance, "removeLast"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void reversedRemoveFirstShouldNotChangeSequence(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - while (!expected.isEmpty()) { - assertEquals(instance._reversed().removeFirst(), expected.remove(expected.size() - 1)); - assertEqualSequence(expected, instance, "removeLast"); - } - } - - @SuppressWarnings("SuspiciousMethodCalls") - @ParameterizedTest - @MethodSource("dataProvider") - public void reversedContainsShouldYieldExpectedValue(@NonNull SetData data) { - SequencedSet instance = newInstance(data.a()); - for (HashCollider k : data.a()) { - assertTrue(instance._reversed().contains(k)); - } - for (HashCollider k : data.c()) { - assertFalse(instance._reversed().contains(k)); - } - assertFalse(instance._reversed().contains(new Object())); - - instance.addAll(data.someAPlusSomeB().asSet()); - for (HashCollider k : data.a()) { - assertTrue(instance._reversed().contains(k)); - } - for (HashCollider k : data.someAPlusSomeB()) { - assertTrue(instance._reversed().contains(k)); - } - for (HashCollider k : data.c()) { - assertFalse(instance._reversed().contains(k)); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeWithFirstElementShouldNotChangeSequence(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - while (!expected.isEmpty()) { - assertTrue(instance.remove(expected.remove(0))); - assertEqualSequence(expected, instance, "remove(firstElement)"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeWithMiddleElementShouldNotChangeSequenc(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - while (!expected.isEmpty()) { - HashCollider removedElement = expected.remove(expected.size() / 2); - boolean hasRemoved = instance.remove(removedElement); - assertTrue(hasRemoved); - assertEqualSequence(expected, instance, "removeMiddle"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addWithNewElementShouldMoveElementToLast(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - for (HashCollider e : data.c()) { - instance.add(e); - assertEquals(e, instance.getLast()); - expected.remove(e); - expected.add(e); - assertEqualSequence(expected, instance, "add"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void reversedAddWithNewElementShouldMoveElementToFirst(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - for (HashCollider e : data.c()) { - instance._reversed().add(e); - assertEquals(e, instance._reversed().getLast()); - expected.remove(e); - expected.add(0, e); - assertEqualSequence(expected, instance, "add"); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void reversedOfReversedShouldHaveSameSequence(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - ArrayList actual = new ArrayList<>(instance._reversed()._reversed()); - assertEquals(expected, actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void reversedShouldHaveReversedSequence(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - List expected = new ArrayList<>(data.a().asSet()); - Collections.reverse(expected); - ArrayList actual = new ArrayList<>(instance._reversed()); - assertEquals(expected, actual); - } - - @SuppressWarnings("unchecked") - @ParameterizedTest - @MethodSource("dataProvider") - public void readOnlyReversedOfReadOnlyReversedShouldHaveSameSequence(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - if (instance instanceof ReadOnlySequencedSet) { - ReadOnlySequencedSet readOnlyInstance = (ReadOnlySequencedSet) instance; - List expected = new ArrayList<>(data.a().asSet()); - ArrayList actual = new ArrayList<>(readOnlyInstance.readOnlyReversed().readOnlyReversed().asSet()); - assertEquals(expected, actual); - } - } - - @SuppressWarnings("unchecked") - @ParameterizedTest - @MethodSource("dataProvider") - public void readOnlyReversedShouldHaveReversedSequence(@NonNull SetData data) throws Exception { - SequencedSet instance = newInstance(data.a()); - if (instance instanceof ReadOnlySequencedSet) { - ReadOnlySequencedSet readOnlyInstance = (ReadOnlySequencedSet) instance; - List expected = new ArrayList<>(data.a().asSet()); - Collections.reverse(expected); - ArrayList actual = new ArrayList<>(readOnlyInstance.readOnlyReversed().asSet()); - assertEquals(expected, actual); - } - } - - protected void assertEqualSequence(Collection expected, SequencedSet actual, String message) { - ArrayList expectedList = new ArrayList<>(expected); - assertEquals(expectedList, new ArrayList<>(actual), message); - if (!expected.isEmpty()) { - assertEquals(expectedList.get(0), actual.getFirst(), message); - assertEquals(expectedList.get(0), actual.iterator().next(), message); - assertEquals(expectedList.get(expectedList.size() - 1), actual.getLast(), message); - assertEquals(expectedList.get(expectedList.size() - 1), actual._reversed().iterator().next(), message); - } - assertEquals(expected.toString(), actual.toString(), message); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractSetLongRunningTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractSetLongRunningTest.java deleted file mode 100644 index 8153a8bf0..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractSetLongRunningTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.jhotdraw8.collection; - -import org.jhotdraw8.collection.computed.ComputedList; -import org.jhotdraw8.collection.readonly.SizeLimitExceededException; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -public abstract class AbstractSetLongRunningTest { - abstract Set createInstance(); - - abstract long maxSize(); - - /** - *
    - *
  1. GIVEN a new list instance
  2. - *
  3. WHEN we add {@link #maxSize()} elements
  4. - *
  5. THEN the list must not throw a {@link SizeLimitExceededException}
  6. - *
  7. WHEN we add one element more - *
  8. THEN the list must throw a {@link SizeLimitExceededException}
  9. - *
- * Should not throw a size limit exception, when we add {@link #maxSize()} elements. - */ - @Test - @Disabled - - public void shouldThrowSizeLimitExceededException() { - Set instance = createInstance(); - ComputedList toBeAdded = new ComputedList<>(maxSize(), i -> i); - instance.addAll(toBeAdded.asList()); - assertEquals(maxSize(), instance.size(), "size"); - assertThrows(SizeLimitExceededException.class, () -> instance.add(maxSize() + 1)); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractSetTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractSetTest.java deleted file mode 100644 index 335701c13..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AbstractSetTest.java +++ /dev/null @@ -1,714 +0,0 @@ -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.readonly.ReadOnlySet; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public abstract class AbstractSetTest { - private static final SetData NO_COLLISION_NICE_KEYS = SetData.newNiceData("no collisions nice keys", -1, 32, 100_000); - private static final SetData NO_COLLISION = SetData.newData("no collisions", -1, 32, 100_000); - private static final SetData ALL_COLLISION = SetData.newData("all collisions", 0, 32, 100_000); - private static final SetData SOME_COLLISION = SetData.newData("some collisions", 0x55555555, 32, 100_000); - - - public static @NonNull Stream dataProvider() { - return Stream.of( - NO_COLLISION_NICE_KEYS, NO_COLLISION, ALL_COLLISION, SOME_COLLISION - ); - } - - - protected void assertEqualSet(@NonNull ReadOnlySet expected, @NonNull Set actual) { - assertEqualSet(expected.asSet(), actual); - } - - protected void assertEqualSet(@NonNull Set expected, @NonNull Set actual) { - assertEquals(expected.size(), actual.size()); - assertEquals(expected.isEmpty(), actual.isEmpty()); - assertEquals(expected.hashCode(), actual.hashCode()); - assertEquals(expected, actual); - assertEquals(actual, expected); - - ArrayList expectedValues = new ArrayList<>(expected); - ArrayList actualValues = new ArrayList<>(actual); - expectedValues.sort(Comparator.comparing(HashCollider::getValue)); - actualValues.sort(Comparator.comparing(HashCollider::getValue)); - assertEquals(expectedValues, actualValues); - } - - protected void assertNotEqualSet(Set expected, Set actual) { - assertNotEquals(expected, actual); - assertNotEquals(actual, expected); - } - - /** - * Creates a new empty instance. - */ - protected abstract @NonNull Set newInstance(); - - /** - * Creates a new instance with the specified expected number of elements - * and load factor. - */ - protected abstract @NonNull Set newInstance(int numElements, float loadFactor); - - /** - * Creates a new instance with the specified map. - */ - protected abstract @NonNull Set newInstance(@NonNull Set m); - - protected abstract @NonNull Set newInstance(@NonNull ReadOnlySet m); - - /** - * Creates a new instance with the specified map. - */ - protected abstract @NonNull Set newInstance(@NonNull Iterable m); - - @ParameterizedTest - @MethodSource("dataProvider") - public void addNullContainsNullShouldReturnTrue(@NonNull SetData data) throws Exception { - Set instance = newInstance(); - assertFalse(instance.contains(null)); - var expected = new LinkedHashSet(); - expected.add(null); - instance.add(null); - assertTrue(instance.contains(null)); - assertEqualSet(expected, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addAllNullContainsNullShouldReturnTrue(@NonNull SetData data) throws Exception { - Set instance = newInstance(); - assertFalse(instance.contains(null)); - var expected = new LinkedHashSet(); - expected.addAll(Collections.singleton(null)); - instance.addAll(Collections.singleton(null)); - assertTrue(instance.contains(null)); - assertEqualSet(expected, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addAllWithCloneShouldReturnFalse(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a); - Set instance2 = toClonedInstance(instance); - assertFalse(instance.addAll(instance2)); - assertEquals(data.a.asSet(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addAllWithContainedElementsShouldReturnFalse(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a); - assertFalse(instance.addAll(data.a.asSet())); - assertEquals(data.a.asSet(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addAllWithNewElementsShouldReturnTrue(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a); - assertTrue(instance.addAll(data.c.asSet())); - LinkedHashSet expected = new LinkedHashSet<>(data.a.asSet()); - expected.addAll(data.c.asSet()); - assertEquals(expected, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addAllWithSameTypeAndAllNewKeysShouldReturnTrue(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a); - Set instance2 = newInstance(data.c); - assertTrue(instance.addAll(instance2)); - - LinkedHashSet expected = new LinkedHashSet<>(data.a.asSet()); - expected.addAll(data.c.asSet()); - assertEqualSet(expected, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addAllWithSameTypeAndSomeNewKeysShouldReturnTrue(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a); - - ArrayList listA = new ArrayList<>(data.a.asSet()); - ArrayList listC = new ArrayList<>(data.c.asSet()); - - Set instance2 = newInstance(); - instance2.addAll(listA.subList(0, listA.size() / 2)); - instance2.addAll(listC.subList(0, listC.size() / 2)); - - LinkedHashSet expected = new LinkedHashSet<>(listA); - LinkedHashSet expected2 = new LinkedHashSet<>(); - expected2.addAll(listA.subList(0, listA.size() / 2)); - expected2.addAll(listC.subList(0, listC.size() / 2)); - assertEqualSet(expected2, instance2); - - assertTrue(instance.addAll(instance2)); - expected.addAll(expected2); - assertEqualSet(expected, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addAllWithSelfShouldReturnFalse(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a); - assertFalse(instance.addAll(instance)); - assertEquals(data.a.asSet(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addAllWithSomeNewKeysShouldReturnTrue(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a); - - ArrayList listA = new ArrayList<>(data.a.asSet()); - ArrayList listC = new ArrayList<>(data.c.asSet()); - ArrayList list = new ArrayList<>(listA.subList(0, listA.size() / 2)); - list.addAll(listC.subList(0, listC.size() / 2)); - assertTrue(instance.addAll(list)); - LinkedHashSet expected = new LinkedHashSet<>(listA); - expected.addAll(list); - assertEqualSet(expected, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addWithContainedElementShouldReturnFalse(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a); - Set expected = new LinkedHashSet<>(data.a.asSet()); - for (HashCollider e : data.a) { - assertFalse(instance.add(e)); - assertEqualSet(expected, instance); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void addWithNewElementShouldReturnTrue(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a); - Set expected = new LinkedHashSet<>(data.a.asSet()); - for (HashCollider e : data.c) { - assertTrue(instance.add(e)); - expected.add(e); - assertEqualSet(expected, instance); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void clearShouldBeIdempotent(@NonNull SetData data) { - Set instance = newInstance(data.a()); - assertNotEqualSet(Collections.emptySet(), instance); - instance.clear(); - assertEqualSet(Collections.emptySet(), instance); - instance.clear(); - assertEqualSet(Collections.emptySet(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void clearShouldYieldEmptySet(@NonNull SetData data) { - Set instance = newInstance(data.a()); - assertNotEqualSet(Collections.emptySet(), instance); - instance.clear(); - assertEqualSet(Collections.emptySet(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void cloneShouldYieldEqualSet(@NonNull SetData data) { - Set instance = newInstance(data.a()); - Set clone = toClonedInstance(instance); - assertEqualSet(data.a().asSet(), clone); - } - - @SuppressWarnings("SuspiciousMethodCalls") - @ParameterizedTest - @MethodSource("dataProvider") - public void containsShouldYieldExpectedValue(@NonNull SetData data) { - Set instance = newInstance(data.a()); - for (HashCollider k : data.a()) { - assertTrue(instance.contains(k)); - } - for (HashCollider k : data.c()) { - assertFalse(instance.contains(k)); - } - assertFalse(instance.contains(new Object())); - - instance.addAll(data.someAPlusSomeB.asSet()); - for (HashCollider k : data.a()) { - assertTrue(instance.contains(k)); - } - for (HashCollider k : data.someAPlusSomeB) { - assertTrue(instance.contains(k)); - } - for (HashCollider k : data.c()) { - assertFalse(instance.contains(k)); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void containsAllShouldYieldExpectedValue(@NonNull SetData data) { - Set instance = newInstance(data.a()); - assertTrue(instance.containsAll(data.a().asSet())); - assertFalse(instance.containsAll(data.b().asSet())); - assertFalse(instance.containsAll(data.someAPlusSomeB().asSet())); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void hashCodeShouldYieldExpectedValue(@NonNull SetData data) { - Set instance = newInstance(data.a()); - LinkedHashSet expected = new LinkedHashSet<>(data.a().asSet()); - assertEquals(expected.hashCode(), instance.hashCode()); - - instance.addAll(data.b().asSet()); - instance.retainAll(data.someAPlusSomeB().asSet()); - expected.addAll(data.b().asSet()); - expected.retainAll(data.someAPlusSomeB().asSet()); - assertEquals(expected.hashCode(), instance.hashCode()); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void equalWithThisShouldYieldTrue(@NonNull SetData data) { - Set instance = newInstance(data.a()); - assertEquals(instance, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void equalsWithCloneShouldYieldTrue(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a()); - Set clone = toClonedInstance(instance); - assertEquals(data.a().asSet(), clone); - assertEquals(instance, clone); - } - - @SuppressWarnings({"ConstantConditions", "SimplifiableAssertion"}) - @ParameterizedTest - @MethodSource("dataProvider") - public void equalsWithNullShouldYieldFalse(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a()); - assertFalse(instance.equals(null)); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void equalsWithObjectShouldYieldFalse(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a()); - assertNotEquals(instance, new Object()); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void iteratorRemoveShouldRemoveElement(@NonNull SetData data) { - Set actual = newInstance(data.a()); - Set expected = new LinkedHashSet<>(data.a().asSet()); - List toRemove = new ArrayList<>(new HashSet<>(data.a().asSet())); - while (!toRemove.isEmpty() && !expected.isEmpty()) { - for (Iterator i = actual.iterator(); i.hasNext(); ) { - HashCollider k = i.next(); - if (k.equals(toRemove.get(0))) { - i.remove(); - toRemove.remove(0); - expected.remove(k); - assertEqualSet(expected, actual); - } - } - } - assertEqualSet(Collections.emptySet(), actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void iteratorRemoveShouldThrowIllegalStateException(@NonNull SetData data) { - Set instance = newInstance(data.a()); - Iterator i = instance.iterator(); - assertThrows(IllegalStateException.class, i::remove); - Iterator k = instance.iterator(); - assertThrows(IllegalStateException.class, k::remove); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void iteratorShouldYieldElements(@NonNull SetData data) { - Set instance = newInstance(data.a()); - Set expected = new LinkedHashSet<>(data.a().asSet()); - List actualList = new ArrayList<>(); - instance.iterator().forEachRemaining(actualList::add); - assertEquals(expected.size(), actualList.size()); - assertEquals(expected, newInstance(actualList)); - } - - @SuppressWarnings("unchecked") - @ParameterizedTest - @MethodSource("dataProvider") - public void toArrayShouldYieldElements(@NonNull SetData data) { - Set instance = newInstance(data.a()); - Set expected = new LinkedHashSet<>(data.a().asSet()); - List actualList = (List) (List) Arrays.asList(instance.toArray()); - assertEquals(expected.size(), actualList.size()); - assertEquals(expected, newInstance(actualList)); - } - - - @ParameterizedTest - @MethodSource("dataProvider") - public void toArrayWithTemplateArgShouldYieldElements(@NonNull SetData data) { - Set instance = newInstance(data.a()); - Set expected = new LinkedHashSet<>(data.a().asSet()); - List actualList = Arrays.asList(instance.toArray(new HashCollider[0])); - assertEquals(expected.size(), actualList.size()); - assertEquals(expected, newInstance(actualList)); - } - - @Test - public void newInstanceCapacityArgsShouldBeEmpty() { - Set actual = newInstance(24, 0.75f); - LinkedHashSet expected = new LinkedHashSet<>(24, 0.75f); - assertEqualSet(expected, actual); - } - - @Test - public void newInstanceNoArgsShouldBeEmpty() { - Set actual = newInstance(); - LinkedHashSet expected = new LinkedHashSet<>(); - assertEqualSet(expected, actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void newInstanceReadOnlySetArgsShouldBeEqualToSet(@NonNull SetData data) { - Set actual = newInstance(data.a()); - assertEqualSet(data.a().asSet(), actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void newInstanceSetArgsOfSameTypeShouldBeEqualToSet(@NonNull SetData data) { - Set actual1 = newInstance(data.a().asSet()); - Set actual = newInstance(actual1); - assertEqualSet(data.a().asSet(), actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void newInstanceSetArgsShouldBeEqualToSet(@NonNull SetData data) { - Set actual = newInstance(data.a().asSet()); - assertEqualSet(data.a().asSet(), actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeAllOfEmptySetShouldReturnFalse(@NonNull SetData data) throws Exception { - Set instance = newInstance(); - assertFalse(instance.removeAll(data.a.asSet())); - assertEqualSet(Collections.emptySet(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeAllWithContainedKeyShouldReturnTrue(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a); - assertTrue(instance.removeAll(data.a.asSet())); - assertEqualSet(Collections.emptySet(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeAllWithEmptyThisShouldReturnFalse(@NonNull SetData data) throws Exception { - Set instance = newInstance(); - assertFalse(instance.removeAll(instance)); - assertEqualSet(Collections.emptySet(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeAllWithNewKeyShouldReturnFalse(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a); - assertFalse(instance.removeAll(data.c.asSet())); - assertEqualSet(data.a, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeAllWithSomeContainedKeyShouldReturnTrue(@NonNull SetData data) throws Exception { - ArrayList listA = new ArrayList<>(data.a.asSet()); - ArrayList listC = new ArrayList<>(data.c.asSet()); - ArrayList list = new ArrayList<>(listA.subList(0, listA.size() / 2)); - list.addAll(listC.subList(0, listC.size() / 2)); - Set instance = newInstance(data.a); - assertTrue(instance.removeAll(list)); - assertEqualSet(new LinkedHashSet<>(listA.subList(listA.size() / 2, listA.size())), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeAllWithThisShouldReturnTrue(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a); - assertTrue(instance.removeAll(instance)); - assertEqualSet(Collections.emptySet(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeWithContainedKeyShouldReturnOldValue(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a); - LinkedHashSet expected = new LinkedHashSet<>(data.a().asSet()); - for (HashCollider e : data.a) { - expected.remove(e); - assertTrue(instance.remove(e)); - assertEqualSet(expected, instance); - } - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void removeWithNewElementShouldReturnFalse(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a); - for (HashCollider e : data.c) { - assertFalse(instance.remove(e)); - assertEqualSet(data.a, instance); - } - } - - @SuppressWarnings("unchecked") - @ParameterizedTest - @MethodSource("dataProvider") - public void serializationShouldYieldSameSet(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a()); - assertEqualSet(data.a().asSet(), instance); - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - try (ObjectOutputStream out = new ObjectOutputStream(buf)) { - out.writeObject(instance); - } - Set deserialized; - try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buf.toByteArray()))) { - deserialized = (Set) in.readObject(); - } - assertEqualSet(data.a().asSet(), deserialized); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void spliteratorShouldYieldElements(@NonNull SetData data) { - Set instance = newInstance(data.a()); - Set expected = new LinkedHashSet<>(data.a().asSet()); - List actualList = new ArrayList<>(); - instance.spliterator().forEachRemaining(actualList::add); - assertEquals(expected.size(), actualList.size()); - assertEquals(expected, newInstance(actualList)); - } - - @SuppressWarnings("SimplifyStreamApiCallChains") - @ParameterizedTest - @MethodSource("dataProvider") - public void streamShouldYieldElements(@NonNull SetData data) { - Set instance = newInstance(data.a()); - Set expected = new LinkedHashSet<>(data.a().asSet()); - List actualList = instance.stream().collect(Collectors.toList()); - assertEquals(expected.size(), actualList.size()); - assertEquals(expected, newInstance(actualList)); - } - - protected abstract @NonNull Set toClonedInstance(@NonNull Set m); - - - @ParameterizedTest - @MethodSource("dataProvider") - public void retainAllWithCloneShouldReturnFalse(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a); - Set instance2 = toClonedInstance(instance); - assertFalse(instance.retainAll(instance2)); - assertEqualSet(data.a, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void retainAllWithContainedElementsShouldReturnFalse(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a); - assertFalse(instance.retainAll(data.a.asSet())); - assertEqualSet(data.a, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void retainAllWithSomeContainedElementsShouldReturnTrue(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a); - Set expected = new LinkedHashSet<>(data.a.asSet()); - assertTrue(instance.retainAll(data.someAPlusSomeB.asSet())); - assertTrue(expected.retainAll(data.someAPlusSomeB.asSet())); - assertEquals(expected, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void retainAllWithNewElementsShouldReturnTrue(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a); - assertTrue(instance.retainAll(data.c.asSet())); - assertEquals(Collections.emptySet(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void retainAllOfEmptySetShouldReturnFalse(@NonNull SetData data) throws Exception { - Set instance = newInstance(); - assertFalse(instance.retainAll(data.c.asSet())); - assertEquals(Collections.emptySet(), instance); - } - - @SuppressWarnings("SuspiciousMethodCalls") - @ParameterizedTest - @MethodSource("dataProvider") - public void retainAllWithEmptySetShouldReturnTrue(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a.asSet()); - assertTrue(instance.retainAll(Collections.emptySet())); - assertEquals(Collections.emptySet(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void retainAllWithSameTypeAndAllNewKeysShouldReturnTrue(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a); - Set instance2 = newInstance(data.c); - assertTrue(instance.retainAll(instance2)); - assertEqualSet(Collections.emptySet(), instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void retainAllWithSameTypeAndSomeNewKeysShouldReturnTrue(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a); - - ArrayList listA = new ArrayList<>(data.a.asSet()); - ArrayList listC = new ArrayList<>(data.c.asSet()); - - Set instance2 = newInstance(); - instance2.addAll(listA.subList(0, listA.size() / 2)); - instance2.addAll(listC.subList(0, listC.size() / 2)); - - LinkedHashSet expected = new LinkedHashSet<>(listA); - LinkedHashSet expected2 = new LinkedHashSet<>(); - expected2.addAll(listA.subList(0, listA.size() / 2)); - expected2.addAll(listC.subList(0, listC.size() / 2)); - assertEqualSet(expected2, instance2); - - assertTrue(instance.retainAll(instance2)); - expected.retainAll(expected2); - assertEqualSet(expected, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void retainAllWithSelfShouldReturnFalse(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a); - assertFalse(instance.retainAll(instance)); - assertEqualSet(data.a, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void retainAllWithSomeNewKeysShouldReturnTrue(@NonNull SetData data) throws Exception { - Set instance = newInstance(data.a); - assertTrue(instance.retainAll(data.someAPlusSomeB.asSet())); - LinkedHashSet expected = new LinkedHashSet<>(data.a.asSet()); - expected.retainAll(data.someAPlusSomeB.asSet()); - assertEqualSet(expected, instance); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void toStringShouldContainAllElements(@NonNull SetData data) { - Set instance = newInstance(); - assertEquals("[]", instance.toString()); - - instance.addAll(data.a.asSet()); - String str = instance.toString(); - assertEquals('[', str.charAt(0)); - assertEquals(']', str.charAt(str.length() - 1)); - LinkedHashSet actual = new LinkedHashSet<>(Arrays.asList(str.substring(1, str.length() - 1).split(", "))); - Set expected = new LinkedHashSet<>(); - data.a.iterator().forEachRemaining(e -> expected.add(e.toString())); - assertEquals(expected, actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void sizeShouldReturnExpectedValue(@NonNull SetData data) { - LinkedHashSet expected = new LinkedHashSet<>(data.a.asSet()); - Set instance = newInstance(); - assertEquals(0, instance.size()); - - instance = newInstance(data.a); - assertEquals(data.a.size(), instance.size()); - - instance.addAll(data.someAPlusSomeB.asSet()); - expected.addAll(data.someAPlusSomeB.asSet()); - assertEquals(expected.size(), instance.size()); - - instance.addAll(data.c.asSet()); - expected.addAll(data.c.asSet()); - assertEquals(expected.size(), instance.size()); - - instance.removeAll(data.someAPlusSomeB.asSet()); - expected.removeAll(data.someAPlusSomeB.asSet()); - assertEquals(expected.size(), instance.size()); - - instance.clear(); - assertEquals(0, instance.size()); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void isEmptyShouldReturnExpectedValue(@NonNull SetData data) { - LinkedHashSet expected = new LinkedHashSet<>(data.a.asSet()); - Set instance = newInstance(); - assertTrue(instance.isEmpty()); - - instance = newInstance(data.a); - assertEquals(data.a.isEmpty(), instance.isEmpty()); - - instance.addAll(data.someAPlusSomeB.asSet()); - expected.addAll(data.someAPlusSomeB.asSet()); - assertEquals(expected.isEmpty(), instance.isEmpty()); - - instance.addAll(data.c.asSet()); - expected.addAll(data.c.asSet()); - assertEquals(expected.isEmpty(), instance.isEmpty()); - - instance.removeAll(data.someAPlusSomeB.asSet()); - expected.removeAll(data.someAPlusSomeB.asSet()); - assertEquals(expected.isEmpty(), instance.isEmpty()); - - instance.clear(); - assertTrue(instance.isEmpty()); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AddOnlyChampSetTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AddOnlyChampSetTest.java deleted file mode 100644 index c50b7b295..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/AddOnlyChampSetTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * @(#)ImmutableAddOnlyChampSetTest.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.junit.jupiter.api.DynamicTest; -import org.junit.jupiter.api.TestFactory; - -import java.util.Arrays; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Random; - -import static org.junit.jupiter.api.Assertions.assertNotSame; -import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.DynamicTest.dynamicTest; - -public class AddOnlyChampSetTest { - - @TestFactory - public @NonNull List dynamicTests() { - return Arrays.asList( - dynamicTest("32-bits hash", () -> doTest(-1)), - dynamicTest("3-bits hash", () -> doTest(7)), - dynamicTest("0-bits hash", () -> doTest(0)) - ); - } - - - void doTest(int hashBitMask) { - int bulkSize = 16; - Random rng = new Random(0); - for (int i = 0; i < 64; i++) { - // values1, values2 are distinct sets of values - LinkedHashSet values1 = new LinkedHashSet<>(); - LinkedHashSet values2 = new LinkedHashSet<>(); - while (values1.size() < bulkSize) { - values1.add(new HashCollider(rng.nextInt(), hashBitMask)); - } - while (values2.size() < bulkSize) { - HashCollider e = new HashCollider(rng.nextInt(), hashBitMask); - if (!values1.contains(e)) { - values2.add(e); - } - } - - testCopyAddAndOfWith0Arg(values1, values2); - testCopyAddAndOfWith1Arg(values1, values2); - } - } - - - private void testCopyAddAndOfWith0Arg(LinkedHashSet values1, LinkedHashSet values2) { - HashCollider firstValue1 = values1.iterator().next(); - HashCollider firstValue2 = values2.iterator().next(); - AddOnlyChampSet actual = AddOnlyChampSet.of(); - AddOnlyChampSet newActual; - - // GIVEN: a set with values1 - for (HashCollider v : values1) { - actual = actual.add(v); - } - - // WHEN: value1 is already in set, then withAdd must yield the same set - newActual = actual.add(firstValue1); - assertSame(newActual, actual); - - // WHEN: value2 is not yet in set, then withAdd must yield a new set - newActual = actual.add(firstValue2); - assertNotSame(newActual, actual); - } - - private void testCopyAddAndOfWith1Arg(LinkedHashSet values1, LinkedHashSet values2) { - HashCollider firstValue1 = values1.iterator().next(); - HashCollider firstValue2 = values2.iterator().next(); - AddOnlyChampSet actual = AddOnlyChampSet.of().add(firstValue1); - AddOnlyChampSet newActual; - - // GIVEN: a set with values1 - for (HashCollider v : values1) { - actual = actual.add(v); - } - - // WHEN: value1 is already in set, then withAdd must yield the same set - newActual = actual.add(firstValue1); - assertSame(newActual, actual); - - // WHEN: value2 is not yet in set, then withAdd must yield a new set - newActual = actual.add(firstValue2); - assertNotSame(newActual, actual); - } -} \ No newline at end of file diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/ChampMapTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/ChampMapTest.java deleted file mode 100644 index 52db0bda8..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/ChampMapTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * @(#)ImmutableChampMapTest.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableMap; -import org.jhotdraw8.collection.readonly.ReadOnlyMap; - -import java.util.Map; - -public class ChampMapTest extends AbstractImmutableMapTest { - @Override - protected @NonNull ChampMap newInstance() { - return ChampMap.of(); - } - - - @Override - protected @NonNull ImmutableMap newInstance(@NonNull Map map) { - return ChampMap.of().putAll(map); - } - - @Override - protected @NonNull ImmutableMap newInstance(@NonNull ReadOnlyMap map) { - return ChampMap.of().putAll(map); - } - - @Override - protected @NonNull ImmutableMap toClonedInstance(@NonNull ImmutableMap m) { - return ChampMap.copyOf(m); - } - - @Override - protected @NonNull ImmutableMap newInstance(@NonNull Iterable> entries) { - return ChampMap.of().putAll(entries); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/ChampSetTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/ChampSetTest.java deleted file mode 100644 index 5c9a6bc23..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/ChampSetTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * @(#)ImmutableChampSetTest.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableSet; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; - -import java.util.LinkedHashSet; -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class ChampSetTest extends AbstractImmutableSetTest { - - - @Override - protected @NonNull ImmutableSet newInstance() { - return ChampSet.of(); - } - - - @Override - protected @NonNull Set toMutableInstance(ImmutableSet m) { - return m.toMutable(); - } - - @Override - protected @NonNull ImmutableSet toImmutableInstance(Set m) { - return ((MutableChampSet) m).toImmutable(); - } - - @Override - protected @NonNull ImmutableSet toClonedInstance(ImmutableSet m) { - return ChampSet.copyOf(m.asSet()); - } - - @Override - protected @NonNull ImmutableSet newInstance(Iterable m) { - return ChampSet.copyOf(m); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testToMutableAddAllWithImmutableTypeAndAllNewKeysShouldReturnTrue(@NonNull SetData data) throws Exception { - ImmutableSet instance = newInstance(data.a); - ImmutableSet instance2 = newInstance(data.c); - MutableChampSet mutableInstance = (MutableChampSet) instance.toMutable(); - assertTrue(mutableInstance.addAll(instance2)); - - LinkedHashSet expected = new LinkedHashSet<>(data.a.asSet()); - expected.addAll(data.c.asSet()); - assertEqualSet(expected, toImmutableInstance(mutableInstance)); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testOfArrayArgShouldYieldExpectedResult(@NonNull SetData data) throws Exception { - ImmutableSet instance = ChampSet.of(data.a().toArray(new HashCollider[0])); - assertEqualSet(data.a, instance); - } -} \ No newline at end of file diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/HashCollider.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/HashCollider.java deleted file mode 100644 index 9fab175a2..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/HashCollider.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * @(#)HashCollider.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection; - -import java.io.Serializable; - -/** - * Elem has a configurable bit mask for its hash code. - * Allowing to run the same test with many or few hash collisions. - */ -public class HashCollider implements Serializable, Cloneable { - private static final long serialVersionUID = 0L; - private final int value; - private final int hash; - private final int hashBitMask; - - public HashCollider(int value, int hashBitMask) { - this.value = value; - this.hashBitMask = hashBitMask; - this.hash = value & hashBitMask; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - HashCollider collider = (HashCollider) o; - return value == collider.value; - } - - @Override - public int hashCode() { - return hash; - } - - @Override - public String toString() { - return Integer.toString(value); - } - - public int getValue() { - return value; - } - - public int getHashBitMask() { - return hashBitMask; - } - - @Override - public HashCollider clone() { - try { - return (HashCollider) super.clone(); - } catch (CloneNotSupportedException e) { - throw new AssertionError(); - } - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/HashSetTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/HashSetTest.java deleted file mode 100644 index 5563d1a12..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/HashSetTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.readonly.ReadOnlySet; - -import java.util.HashSet; -import java.util.Set; - -public class HashSetTest extends AbstractSetTest { - @Override - protected @NonNull Set newInstance() { - return new HashSet<>(); - } - - @Override - protected @NonNull Set newInstance(int numElements, float loadFactor) { - return new HashSet<>(); - } - - @Override - protected @NonNull Set newInstance(Set m) { - return new HashSet<>(m); - } - - @Override - protected @NonNull Set newInstance(ReadOnlySet m) { - return new HashSet<>(m.asSet()); - } - - - @SuppressWarnings("unchecked") - @Override - protected @NonNull Set toClonedInstance(Set m) { - return (Set) ((HashSet) m).clone(); - } - - @Override - protected @NonNull Set newInstance(Iterable m) { - HashSet s = new HashSet<>(); - m.iterator().forEachRemaining(s::add); - return s; - - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MapData.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MapData.java deleted file mode 100644 index 696789be4..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MapData.java +++ /dev/null @@ -1,124 +0,0 @@ -package org.jhotdraw8.collection; - -import org.jhotdraw8.collection.facade.ReadOnlyMapFacade; -import org.jhotdraw8.collection.readonly.ReadOnlyMap; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Random; -import java.util.Set; - -/** - * The test data. - */ -public final class MapData { - private final String name; - public final ReadOnlyMap a; - public final ReadOnlyMap aWithDifferentValues; - public final ReadOnlyMap c; - private final ReadOnlyMap someAPlusSomeB; - public final ReadOnlyMap b; - - /** - * Creates a new instance with 3 maps of the same non-empty size. - * - * @param name the name of the data - * @param a a non-empty map, all values are distinct - * @param aWithDifferentValues a map with identical keys but different values from a, - * all values are distinct from the values in a - * and from other values in b - * @param c a map with different keys and values from a, - * all values are distinct from the values in a. - */ - MapData(String name, ReadOnlyMap a, - ReadOnlyMap aWithDifferentValues, - ReadOnlyMap b, - ReadOnlyMap c) { - this.name = name; - this.a = a; - this.aWithDifferentValues = aWithDifferentValues; - this.c = c; - this.b = b; - - LinkedHashMap someAPlusSomeB = new LinkedHashMap<>(); - ArrayList> aPlusB = new ArrayList<>(a.size() + b.size()); - aPlusB.addAll(a.readOnlyEntrySet().asSet()); - aPlusB.addAll(b.readOnlyEntrySet().asSet()); - aPlusB.subList(a.size() / 2, a.size() + (b.size() + 1) / 2) - .iterator().forEachRemaining(e -> someAPlusSomeB.put(e.getKey(), e.getValue())); - this.someAPlusSomeB = new ReadOnlyMapFacade<>(someAPlusSomeB); - - } - - @Override - public String toString() { - return name; - } - - public String name() { - return name; - } - - public ReadOnlyMap a() { - return a; - } - - public ReadOnlyMap aWithDifferentValues() { - return aWithDifferentValues; - } - - public ReadOnlyMap b() { - return b; - } - - public ReadOnlyMap someAPlusSomeB() { - return someAPlusSomeB; - } - - public ReadOnlyMap c() { - return c; - } - - - public static MapData newData(String name, int hashBitMask, int size, int bound) { - Random rng = new Random(0); - LinkedHashMap a = new LinkedHashMap<>(size * 2); - LinkedHashMap b = new LinkedHashMap<>(size * 2); - LinkedHashMap aWithDifferentValues = new LinkedHashMap<>(size * 2); - LinkedHashMap c = new LinkedHashMap<>(size * 2); - LinkedHashSet usedValues = new LinkedHashSet<>(); - for (int i = 0; i < size; i++) { - int keyA = createNewValue(rng, usedValues, bound); - int keyB = createNewValue(rng, usedValues, bound); - int keyC = createNewValue(rng, usedValues, bound); - int valueA = createNewValue(rng, usedValues, bound); - int valueDifferentFromA = createNewValue(rng, usedValues, bound); - int valueB = createNewValue(rng, usedValues, bound); - int valueC = createNewValue(rng, usedValues, bound); - a.put(new HashCollider(keyA, hashBitMask), new HashCollider(valueA, hashBitMask)); - aWithDifferentValues.put(new HashCollider(keyA, hashBitMask), new HashCollider(valueDifferentFromA, hashBitMask)); - b.put(new HashCollider(keyB, hashBitMask), new HashCollider(valueB, hashBitMask)); - c.put(new HashCollider(keyC, hashBitMask), new HashCollider(valueC, hashBitMask)); - } - return new MapData(name, - new ReadOnlyMapFacade<>(a), - new ReadOnlyMapFacade<>(aWithDifferentValues), - new ReadOnlyMapFacade<>(b), - new ReadOnlyMapFacade<>(c)); - } - - private static int createNewValue(Random rng, Set usedValues, int bound) { - int value; - int count = 0; - do { - value = rng.nextInt(bound); - count++; - if (count >= bound) { - throw new RuntimeException("error in rng"); - } - } while (!usedValues.add(value)); - return value; - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MapFacadeTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MapFacadeTest.java deleted file mode 100644 index df9bc4d98..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MapFacadeTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.facade.MapFacade; - -import java.util.HashMap; -import java.util.Map; - -public class MapFacadeTest extends AbstractMapTest { - @Override - protected @NonNull Map newInstance() { - return new MapFacade<>(new HashMap<>()); - } - - @Override - protected @NonNull Map newInstance(int numElements, float loadFactor) { - return new MapFacade<>(new HashMap<>((int) (numElements / loadFactor), loadFactor)); - } - - @Override - protected @NonNull Map newInstance(Map m) { - return new MapFacade<>(new HashMap<>(m)); - } - - @Override - protected @NonNull Map toClonedInstance(Map m) { - return new MapFacade<>(new HashMap<>(m)); - } - - @Override - protected @NonNull Map newInstance(@NonNull Iterable> m) { - HashMap i = new HashMap<>(); - for (Map.Entry e : m) { - i.put(e.getKey(), e.getValue()); - } - return new MapFacade<>(i); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableChampMapTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableChampMapTest.java deleted file mode 100644 index ebfb20cea..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableChampMapTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class MutableChampMapTest extends AbstractMapTest { - @Override - protected @NonNull Map newInstance() { - return new MutableChampMap<>(); - } - - @Override - protected @NonNull Map newInstance(int numElements, float loadFactor) { - return new MutableChampMap<>(); - } - - @Override - protected @NonNull Map newInstance(Map m) { - return new MutableChampMap<>(m); - } - - @Override - protected @NonNull Map newInstance(@NonNull Iterable> m) { - return new MutableChampMap<>(m); - } - - - @Override - protected @NonNull Map toClonedInstance(Map m) { - return ((MutableChampMap) m).clone(); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testNewInstanceReadOnlyArgOfDifferentTypeShouldBeEqualToArg(MapData data) { - Map actual = new MutableChampMap<>(data.a()); - assertEqualMap(data.a(), actual); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testIteratorShouldYieldExpectedEntries(MapData data) throws Exception { - Map instance = newInstance(data.a); - List> actualList = new ArrayList<>(); - LinkedHashMap actualMap = new LinkedHashMap<>(); - ((MutableChampMap) instance).iterator().forEachRemaining(actualList::add); - ((MutableChampMap) instance).iterator().forEachRemaining(e -> actualMap.put(e.getKey(), e.getValue())); - assertEquals(data.a.size(), actualList.size()); - assertEqualMap(data.a, actualMap); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableChampSetLongRunningTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableChampSetLongRunningTest.java deleted file mode 100644 index d259f26a2..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableChampSetLongRunningTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.jhotdraw8.collection; - -import org.junit.Ignore; - -import java.util.Set; - -@Ignore -public class MutableChampSetLongRunningTest extends AbstractSetLongRunningTest { - - @Override - Set createInstance() { - return new MutableChampSet<>(); - } - - @Override - long maxSize() { - return new MutableChampSet<>().maxSize(); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableChampSetTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableChampSetTest.java deleted file mode 100644 index cf424a9e0..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableChampSetTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.readonly.ReadOnlySet; - -import java.util.Set; - -public class MutableChampSetTest extends AbstractSetTest { - @Override - protected @NonNull Set newInstance() { - return new MutableChampSet<>(); - } - - @Override - protected @NonNull Set newInstance(int numElements, float loadFactor) { - return new MutableChampSet<>(); - } - - @Override - protected @NonNull Set newInstance(Set m) { - return new MutableChampSet<>(m); - } - - @Override - protected @NonNull Set newInstance(ReadOnlySet m) { - return new MutableChampSet<>(m); - } - - @Override - protected @NonNull Set toClonedInstance(Set m) { - return ((MutableChampSet) m).clone(); - } - - @Override - protected @NonNull Set newInstance(Iterable m) { - return new MutableChampSet<>(m); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorListLongRunningTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorListLongRunningTest.java deleted file mode 100644 index f00dc95ac..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorListLongRunningTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.jhotdraw8.collection; - -import org.junit.Ignore; - -import java.util.List; - -@Ignore -public class MutableVectorListLongRunningTest extends AbstractListLongRunningTest { - - @Override - List createInstance() { - return new MutableVectorList<>(); - } - - @Override - long maxSize() { - return new MutableVectorList<>().maxSize(); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorListTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorListTest.java deleted file mode 100644 index 280f65235..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorListTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.sequenced.SequencedCollection; - -import java.util.List; - -public class MutableVectorListTest extends AbstractListTest { - @Override - protected @NonNull SequencedCollection newInstance() { - return new MutableVectorList(); - } - - @Override - protected @NonNull List newListInstance() { - return new MutableVectorList(); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorMapTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorMapTest.java deleted file mode 100644 index a2bfe5148..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorMapTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * @(#)SequencedChampMapTest.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableSequencedMap; -import org.jhotdraw8.collection.sequenced.SequencedMap; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; - -import java.util.Map; - -public class MutableVectorMapTest extends AbstractSequencedMapTest { - @Override - protected @NonNull MutableVectorMap newInstance() { - return new MutableVectorMap<>(); - } - - @Override - protected @NonNull MutableVectorMap newInstance(int numElements, float loadFactor) { - return new MutableVectorMap<>(); - } - - @Override - protected @NonNull MutableVectorMap newInstance(@NonNull Map m) { - return new MutableVectorMap<>(m); - } - - @Override - protected @NonNull MutableVectorMap newInstance(@NonNull Iterable> m) { - return new MutableVectorMap<>(m); - } - - @Override - protected @NonNull ImmutableSequencedMap toImmutableInstance(@NonNull Map m) { - return ((MutableVectorMap) m).toImmutable(); - } - - @Override - protected @NonNull SequencedMap toClonedInstance(@NonNull Map m) { - return ((MutableVectorMap) m).clone(); - } - - @ParameterizedTest - @MethodSource("dataProvider") - public void testConstructorWithReadOnlyArgYieldsExpectedMap(@NonNull MapData data) throws Exception { - Map instance = new MutableVectorMap<>(data.a()); - assertEqualMap(data.a(), instance); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorSetTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorSetTest.java deleted file mode 100644 index 5c199d76e..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/MutableVectorSetTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * @(#)MutableVectorSetTest.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableSequencedSet; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedSet; -import org.jhotdraw8.collection.readonly.ReadOnlySet; -import org.jhotdraw8.collection.sequenced.SequencedSet; - -import java.util.Set; - -public class MutableVectorSetTest extends AbstractSequencedSetTest { - @Override - protected @NonNull SequencedSet newInstance() { - return new MutableVectorSet<>(); - } - - @Override - protected @NonNull SequencedSet newInstance(int numElements, float loadFactor) { - return new MutableVectorSet<>(); - } - - @Override - protected @NonNull SequencedSet newInstance(Set m) { - return new MutableVectorSet<>(m); - } - - @Override - protected @NonNull SequencedSet newInstance(ReadOnlySet m) { - return new MutableVectorSet<>(m); - } - - @Override - protected @NonNull ImmutableSequencedSet toImmutableInstance(Set m) { - return new MutableVectorSet<>(m).toImmutable(); - } - - @Override - protected @NonNull SequencedSet toClonedInstance(Set m) { - return ((MutableVectorSet) m).clone(); - } - - @Override - protected @NonNull SequencedSet newInstance(SequencedSet m) { - return new MutableVectorSet<>(m); - } - - @Override - protected @NonNull SequencedSet newInstance(ReadOnlySequencedSet m) { - return new MutableVectorSet<>(m); - } - - @Override - protected @NonNull ImmutableSequencedSet toImmutableInstance(SequencedSet m) { - return ((MutableVectorSet) m).toImmutable(); - } - - @Override - protected @NonNull SequencedSet toClonedInstance(SequencedSet m) { - return ((MutableVectorSet) m).clone(); - } - - @Override - protected @NonNull SequencedSet newInstance(Iterable m) { - return new MutableVectorSet<>(m); - } - - @Override - public void addLastWithContainedElementShouldMoveElementToLast(@NonNull SetData data) throws Exception { - super.addLastWithContainedElementShouldMoveElementToLast(data); - } - - @Override - public void iteratorRemoveShouldRemoveElement(@NonNull SetData data) { - super.iteratorRemoveShouldRemoveElement(data); - } - - @Override - public void reversedAddFirstWithContainedElementShouldMoveElementToLast(@NonNull SetData data) throws Exception { - super.reversedAddFirstWithContainedElementShouldMoveElementToLast(data); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/OrderedPairTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/OrderedPairTest.java deleted file mode 100755 index 187b4b651..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/OrderedPairTest.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * @(#)OrderedPairTest.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.pair.SimpleOrderedPair; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class OrderedPairTest { - @Test - public void testNonNull() { - SimpleOrderedPair<@NonNull Integer, @NonNull Integer> op = new SimpleOrderedPair<>(3, 5); - int sum = op.first() + op.second(); - assertEquals(8, sum); - } - - @Test - public void testNullable() { - SimpleOrderedPair<@Nullable Integer, @Nullable Integer> op = new SimpleOrderedPair<>(3, 5); - int sum = op.first() + op.second(); - assertEquals(8, sum); - } -} \ No newline at end of file diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/SetData.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/SetData.java deleted file mode 100644 index 1792250b8..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/SetData.java +++ /dev/null @@ -1,123 +0,0 @@ -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.facade.ReadOnlySetFacade; -import org.jhotdraw8.collection.readonly.ReadOnlySet; - -import java.util.ArrayList; -import java.util.LinkedHashSet; -import java.util.Random; -import java.util.Set; - -/** - * The test data. - */ -public final class SetData { - private final String name; - public final ReadOnlySet a; - public final ReadOnlySet b; - public final ReadOnlySet someAPlusSomeB; - public final ReadOnlySet c; - - /** - * Creates a new instance with 3 maps of the same non-empty size. - * - * @param name the name of the data - * @param a a non-empty set that is disjoint from the other sets - * @param b a non-empty set that is disjoint from the other sets - * @param c a non-empty set that is disjoint from the other sets - */ - SetData(String name, ReadOnlySet a, - ReadOnlySet b, - ReadOnlySet c) { - this.name = name; - this.a = a; - this.b = b; - this.c = c; - - LinkedHashSet someAPlusSomeB = new LinkedHashSet<>(); - ArrayList aPlusB = new ArrayList<>(a.size() + b.size()); - aPlusB.addAll(a.asSet()); - aPlusB.addAll(b.asSet()); - someAPlusSomeB.addAll(aPlusB.subList(a.size() / 2, a.size() + (b.size() + 1) / 2)); - this.someAPlusSomeB = new ReadOnlySetFacade<>(someAPlusSomeB); - } - - public ReadOnlySet a() { - return a; - } - - public ReadOnlySet c() { - return c; - } - - public ReadOnlySet b() { - return b; - } - - public ReadOnlySet someAPlusSomeB() { - return someAPlusSomeB; - } - - public String name() { - return name; - } - - @Override - public String toString() { - return name; - } - - - public static @NonNull SetData newData(@NonNull String name, int hashBitMask, int size, int bound) { - Random rng = new Random(0); - LinkedHashSet a = new LinkedHashSet<>(size * 2); - LinkedHashSet b = new LinkedHashSet<>(size * 2); - LinkedHashSet c = new LinkedHashSet<>(size * 2); - LinkedHashSet usedValues = new LinkedHashSet<>(); - for (int i = 0; i < size; i++) { - int keyA = createNewValue(rng, usedValues, bound); - int keyC = createNewValue(rng, usedValues, bound); - int keyB = createNewValue(rng, usedValues, bound); - b.add(new HashCollider(keyB, hashBitMask)); - a.add(new HashCollider(keyA, hashBitMask)); - c.add(new HashCollider(keyC, hashBitMask)); - } - - return new SetData(name, - new ReadOnlySetFacade<>(a), - new ReadOnlySetFacade<>(b), - new ReadOnlySetFacade<>(c)); - } - - public static @NonNull SetData newNiceData(String name, int hashBitMask, int size, int bound) { - int count = 0; - LinkedHashSet a = new LinkedHashSet<>(size * 2); - LinkedHashSet b = new LinkedHashSet<>(size * 2); - LinkedHashSet c = new LinkedHashSet<>(size * 2); - for (int i = 0; i < size; i++) { - int keyA = count++; - a.add(new HashCollider(keyA, hashBitMask)); - b.add(new HashCollider(keyA + size, hashBitMask)); - c.add(new HashCollider(keyA + size * 2, hashBitMask)); - } - return new SetData(name, - new ReadOnlySetFacade<>(a), - new ReadOnlySetFacade<>(b), - new ReadOnlySetFacade<>(c)); - } - - private static int createNewValue(@NonNull Random rng, @NonNull Set usedValues, int bound) { - int value; - int count = 0; - do { - value = rng.nextInt(bound); - count++; - if (count >= bound) { - throw new RuntimeException("error in rng"); - } - } while (!usedValues.add(value)); - return value; - } - -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorListTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorListTest.java deleted file mode 100644 index 8230d2ea2..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorListTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.facade.MutableListFacade; -import org.jhotdraw8.collection.sequenced.SequencedCollection; - -import java.util.List; - -public class VectorListTest extends AbstractListTest { - @Override - protected @NonNull SequencedCollection newInstance() { - return new MutableListFacade(VectorList.of()); - } - - @Override - protected @NonNull List newListInstance() { - return new MutableListFacade(VectorList.of()); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorMapTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorMapTest.java deleted file mode 100644 index 7bff7e14e..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorMapTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * @(#)ImmutableSequencedChampMapTest.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableMap; -import org.jhotdraw8.collection.readonly.ReadOnlyMap; - -import java.util.Map; - -public class VectorMapTest extends AbstractImmutableSequencedMapTest { - @Override - protected @NonNull VectorMap newInstance() { - return VectorMap.of(); - } - - - @Override - protected @NonNull VectorMap newInstance(@NonNull Map map) { - return VectorMap.of().putAll(map); - } - - @Override - protected @NonNull VectorMap newInstance(@NonNull ReadOnlyMap map) { - return VectorMap.of().putAll(map); - } - - @Override - protected @NonNull VectorMap toClonedInstance(@NonNull ImmutableMap m) { - return VectorMap.copyOf(m); - } - - @Override - protected @NonNull VectorMap newInstance(@NonNull Iterable> entries) { - return VectorMap.of().putAll(entries); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorSetTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorSetTest.java deleted file mode 100644 index 8d5e09102..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/VectorSetTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * @(#)ImmutableVectorChampSetTest.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableSet; -import org.jhotdraw8.collection.sequenced.SequencedSet; - -import java.util.Set; - -public class VectorSetTest extends AbstractImmutableSequencedSetTest { - - - @Override - protected @NonNull VectorSet newInstance() { - return VectorSet.of(); - } - - - @Override - protected @NonNull SequencedSet toMutableInstance(ImmutableSet m) { - return ((VectorSet) m).toMutable(); - } - - @Override - protected @NonNull VectorSet toImmutableInstance(Set m) { - return ((MutableVectorSet) m).toImmutable(); - } - - @Override - protected @NonNull VectorSet toClonedInstance(ImmutableSet m) { - return VectorSet.copyOf(m.asSet()); - } - - @Override - protected @NonNull VectorSet newInstance(Iterable m) { - return VectorSet.copyOf(m); - } -} \ No newline at end of file diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/computed/ComputedListTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/computed/ComputedListTest.java deleted file mode 100644 index 4113d4059..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/computed/ComputedListTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.jhotdraw8.collection.computed; - -import org.jhotdraw8.collection.AbstractReadOnlyListTest; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class ComputedListTest extends AbstractReadOnlyListTest { - @Test - public void shouldBeEqual() { - List expected = new ArrayList<>(5); - for (int i = 5; i < 10; i++) expected.add(i); - - ComputedList instance = new ComputedList<>(5, 10, i -> (int) i); - assertEqualList(expected, instance); - } - - @Test - public void shouldBeEqualWhenDescending() { - List expected = new ArrayList<>(5); - for (int i = 5; i < 10; i++) expected.add(i); - Collections.reverse(expected); - - ComputedList instance = new ComputedList<>(5, 10, i -> (int) i, true); - assertEqualList(expected, instance); - } - - @Test - public void shouldBeEqualWhenReversed() { - List expected = new ArrayList<>(5); - for (int i = 5; i < 10; i++) expected.add(i); - Collections.reverse(expected); - - ComputedList instance = new ComputedList<>(5, 10, i -> (int) i); - ComputedList actual = instance.readOnlyReversed(); - assertEqualList(expected, actual); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ImmutableMapFacadeTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ImmutableMapFacadeTest.java deleted file mode 100644 index 3dd180495..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ImmutableMapFacadeTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * @(#)ImmutableMapFacadeTest.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.facade; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.AbstractImmutableMapTest; -import org.jhotdraw8.collection.immutable.ImmutableMap; -import org.jhotdraw8.collection.readonly.ReadOnlyMap; - -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.function.Function; - -public class ImmutableMapFacadeTest extends AbstractImmutableMapTest { - @SuppressWarnings("unchecked") - @Override - protected @NonNull ImmutableMapFacade newInstance() { - Function, Map> cloneFunction = t -> (Map) ((LinkedHashMap) t).clone(); - return new ImmutableMapFacade<>(new LinkedHashMap<>(), - cloneFunction); - } - - @Override - protected @NonNull ImmutableMap newInstance(@NonNull Map map) { - return this.newInstance().putAll(map); - } - - @Override - protected @NonNull ImmutableMap newInstance(@NonNull ReadOnlyMap map) { - return this.newInstance().putAll(map); - } - - @Override - protected @NonNull ImmutableMap toClonedInstance(@NonNull ImmutableMap m) { - return this.newInstance().putAll(m); - } - - @Override - protected @NonNull ImmutableMap newInstance(@NonNull Iterable> entries) { - return this.newInstance().putAll(entries); - } - -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ImmutableSetFacadeTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ImmutableSetFacadeTest.java deleted file mode 100644 index b48019857..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ImmutableSetFacadeTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * @(#)ImmutableSetFacadeTest.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.facade; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.AbstractImmutableSetTest; -import org.jhotdraw8.collection.immutable.ImmutableSet; -import org.jhotdraw8.collection.readonly.ReadOnlySet; - -import java.util.LinkedHashSet; -import java.util.Set; -import java.util.function.Function; - -public class ImmutableSetFacadeTest extends AbstractImmutableSetTest { - - - @SuppressWarnings("unchecked") - @Override - protected @NonNull ImmutableSet newInstance() { - Function, Set> cloneFunction = e -> - (Set) ((LinkedHashSet) e).clone(); - return new ImmutableSetFacade<>(new LinkedHashSet<>(), cloneFunction); - } - - - @Override - protected @NonNull Set toMutableInstance(ImmutableSet m) { - return m.toMutable(); - } - - @SuppressWarnings("unchecked") - @Override - protected @NonNull ImmutableSet toImmutableInstance(Set m) { - Function, Set> cloneFunction = e -> - (Set) ((LinkedHashSet) e).clone(); - return new ImmutableSetFacade<>(m, cloneFunction); - } - - @SuppressWarnings("unchecked") - @Override - protected @NonNull ImmutableSet toClonedInstance(ImmutableSet m) { - Function, Set> cloneFunction = e -> - (Set) ((LinkedHashSet) e).clone(); - return new ImmutableSetFacade<>(m.toMutable(), cloneFunction); - } - - @SuppressWarnings("unchecked") - @Override - protected @NonNull ImmutableSet newInstance(Iterable m) { - Function, Set> cloneFunction = e -> - (Set) ((LinkedHashSet) e).clone(); - if (m instanceof ReadOnlySet) { - return new ImmutableSetFacade<>(new LinkedHashSet<>(((ReadOnlySet) m).asSet()), cloneFunction); - } - return new ImmutableSetFacade<>((Set) m, cloneFunction); - } - - -} \ No newline at end of file diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/ChampSetGuavaTests.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/ChampSetGuavaTests.java deleted file mode 100644 index 629df2a94..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/ChampSetGuavaTests.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * @(#)ChampSetGuavaTests.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.guava; - -import com.google.common.collect.testing.MinimalCollection; -import com.google.common.collect.testing.SetTestSuiteBuilder; -import com.google.common.collect.testing.TestStringSetGenerator; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.collect.testing.features.CollectionSize; -import com.google.common.collect.testing.features.SetFeature; -import junit.framework.Test; -import junit.framework.TestSuite; -import org.jhotdraw8.collection.ChampSet; -import org.jhotdraw8.collection.facade.MutableSetFacade; - -import java.lang.reflect.Method; -import java.util.Collection; -import java.util.Collections; -import java.util.Set; - -/** - * Tests {@link ChampSet} with the Guava test suite. - */ - -public class ChampSetGuavaTests { - - public static Test suite() { - return new ChampSetGuavaTests().allTests(); - } - - public Test allTests() { - TestSuite suite = new TestSuite(ChampSet.class.getSimpleName()); - suite.addTest(testsForTrieSet()); - return suite; - } - - public Test testsForTrieSet() { - return SetTestSuiteBuilder.using( - new TestStringSetGenerator() { - @Override - public Set create(String[] elements) { - return new MutableSetFacade<>( - ChampSet.copyOf(MinimalCollection.of(elements))); - } - }) - .named(ChampSet.class.getSimpleName()) - .withFeatures( - SetFeature.GENERAL_PURPOSE, - CollectionFeature.ALLOWS_NULL_VALUES, - CollectionFeature.ALLOWS_NULL_QUERIES, - //CollectionFeature.SERIALIZABLE, - CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION, - CollectionSize.ANY) - .suppressing(suppressForTrieSet()) - .createTestSuite(); - } - - protected Collection suppressForTrieSet() { - return Collections.emptySet(); - } - -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/MutableChampMapGuavaTests.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/MutableChampMapGuavaTests.java deleted file mode 100644 index 5dc0376d5..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/MutableChampMapGuavaTests.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * @(#)ChampMapGuavaTests.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.guava; - -import com.google.common.collect.testing.MapTestSuiteBuilder; -import com.google.common.collect.testing.TestStringMapGenerator; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.collect.testing.features.CollectionSize; -import com.google.common.collect.testing.features.MapFeature; -import junit.framework.Test; -import junit.framework.TestSuite; -import org.jhotdraw8.collection.MutableChampMap; - -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -/** - * Tests {@link MutableChampMap} with the Guava test suite. - */ -public class MutableChampMapGuavaTests { - - public static Test suite() { - return new MutableChampMapGuavaTests().allTests(); - } - - public Test allTests() { - TestSuite suite = new TestSuite(MutableChampMap.class.getSimpleName()); - suite.addTest(testsForTrieMap()); - return suite; - } - - public Test testsForTrieMap() { - return MapTestSuiteBuilder.using( - new TestStringMapGenerator() { - @Override - protected Map create(Map.Entry[] entries) { - return new MutableChampMap<>(Arrays.asList(entries)); - } - }) - .named(MutableChampMap.class.getSimpleName()) - .withFeatures( - MapFeature.GENERAL_PURPOSE, - MapFeature.ALLOWS_NULL_KEYS, - MapFeature.ALLOWS_NULL_VALUES, - MapFeature.ALLOWS_ANY_NULL_QUERIES, - MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION, - CollectionFeature.SUPPORTS_ITERATOR_REMOVE, - CollectionFeature.SERIALIZABLE, - CollectionSize.ANY) - .suppressing(suppressForRobinHoodHashMap()) - .createTestSuite(); - } - - protected Collection suppressForRobinHoodHashMap() { - return Collections.emptySet(); - } - - -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/MutableChampSetGuavaTests.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/MutableChampSetGuavaTests.java deleted file mode 100644 index bee9036a6..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/MutableChampSetGuavaTests.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * @(#)ChampSetGuavaTests.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.guava; - -import com.google.common.collect.testing.MinimalCollection; -import com.google.common.collect.testing.SetTestSuiteBuilder; -import com.google.common.collect.testing.TestStringSetGenerator; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.collect.testing.features.CollectionSize; -import com.google.common.collect.testing.features.SetFeature; -import junit.framework.Test; -import junit.framework.TestSuite; -import org.jhotdraw8.collection.MutableChampSet; - -import java.lang.reflect.Method; -import java.util.Collection; -import java.util.Collections; -import java.util.Set; - -/** - * Tests {@link MutableChampSet} with the Guava test suite. - */ - -public class MutableChampSetGuavaTests { - - public static Test suite() { - return new MutableChampSetGuavaTests().allTests(); - } - - public Test allTests() { - TestSuite suite = new TestSuite(MutableChampSet.class.getSimpleName()); - suite.addTest(testsForTrieSet()); - return suite; - } - - public Test testsForTrieSet() { - return SetTestSuiteBuilder.using( - new TestStringSetGenerator() { - @Override - public Set create(String[] elements) { - return new MutableChampSet<>(MinimalCollection.of(elements)); - } - }) - .named(MutableChampSet.class.getSimpleName()) - .withFeatures( - SetFeature.GENERAL_PURPOSE, - CollectionFeature.ALLOWS_NULL_VALUES, - CollectionFeature.ALLOWS_NULL_QUERIES, - CollectionFeature.SERIALIZABLE, - CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION, - CollectionSize.ANY) - .suppressing(suppressForTrieSet()) - .createTestSuite(); - } - - protected Collection suppressForTrieSet() { - return Collections.emptySet(); - } - -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/MutableVectorListGuavaTests.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/MutableVectorListGuavaTests.java deleted file mode 100644 index b852d5e96..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/MutableVectorListGuavaTests.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * @(#)ChampSetGuavaTests.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.guava; - -import com.google.common.collect.testing.ListTestSuiteBuilder; -import com.google.common.collect.testing.MinimalCollection; -import com.google.common.collect.testing.TestStringListGenerator; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.collect.testing.features.CollectionSize; -import com.google.common.collect.testing.features.ListFeature; -import junit.framework.Test; -import junit.framework.TestSuite; -import org.jhotdraw8.collection.MutableVectorList; - -import java.lang.reflect.Method; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -/** - * Tests {@link MutableVectorList} with the Guava test suite. - */ - -public class MutableVectorListGuavaTests { - - public static Test suite() { - return new MutableVectorListGuavaTests().allTests(); - } - - public Test allTests() { - TestSuite suite = new TestSuite(MutableVectorList.class.getSimpleName()); - suite.addTest(testsForList()); - return suite; - } - - public Test testsForList() { - return ListTestSuiteBuilder.using( - new TestStringListGenerator() { - @Override - public List create(String[] elements) { - return new MutableVectorList<>(MinimalCollection.of(elements)); - } - }) - .named(MutableVectorList.class.getSimpleName()) - .withFeatures( - ListFeature.GENERAL_PURPOSE, - CollectionFeature.ALLOWS_NULL_VALUES, - CollectionFeature.ALLOWS_NULL_QUERIES, - CollectionFeature.SERIALIZABLE, - CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION, - CollectionSize.ANY) - .suppressing(suppressForTrieSet()) - .createTestSuite(); - } - - protected Collection suppressForTrieSet() { - return Collections.emptySet(); - } - -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/MutableVectorMapGuavaTests.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/MutableVectorMapGuavaTests.java deleted file mode 100644 index e02ef24a6..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/MutableVectorMapGuavaTests.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * @(#)SeqChampMapGuavaTests.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.guava; - -import com.google.common.collect.testing.MapTestSuiteBuilder; -import com.google.common.collect.testing.TestStringMapGenerator; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.collect.testing.features.CollectionSize; -import com.google.common.collect.testing.features.MapFeature; -import junit.framework.Test; -import junit.framework.TestSuite; -import org.jhotdraw8.collection.MutableVectorMap; - -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -/** - * Tests {@link MutableVectorMap} with the Guava test suite. - */ - -public class MutableVectorMapGuavaTests { - - public static Test suite() { - return new MutableVectorMapGuavaTests().allTests(); - } - - public Test allTests() { - TestSuite suite = new TestSuite(MutableVectorMap.class.getSimpleName()); - suite.addTest(testsForLinkedTrieMap()); - return suite; - } - - public Test testsForLinkedTrieMap() { - return MapTestSuiteBuilder.using( - new TestStringMapGenerator() { - @Override - protected Map create(Map.Entry[] entries) { - return new MutableVectorMap<>(Arrays.asList(entries)); - } - }) - .named(MutableVectorMap.class.getSimpleName()) - .withFeatures( - MapFeature.GENERAL_PURPOSE, - MapFeature.ALLOWS_NULL_KEYS, - MapFeature.ALLOWS_NULL_VALUES, - MapFeature.ALLOWS_ANY_NULL_QUERIES, - MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION, - CollectionFeature.SUPPORTS_ITERATOR_REMOVE, - CollectionFeature.KNOWN_ORDER, - CollectionFeature.SERIALIZABLE, - CollectionSize.ANY) - .suppressing(suppressForRobinHoodHashMap()) - .createTestSuite(); - } - - protected Collection suppressForRobinHoodHashMap() { - return Collections.emptySet(); - } - - -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/MutableVectorSetGuavaTests.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/MutableVectorSetGuavaTests.java deleted file mode 100644 index b218a2b9b..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/MutableVectorSetGuavaTests.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * @(#)SeqChampSetGuavaTests.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.guava; - -import com.google.common.collect.testing.MinimalCollection; -import com.google.common.collect.testing.SetTestSuiteBuilder; -import com.google.common.collect.testing.TestStringSetGenerator; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.collect.testing.features.CollectionSize; -import com.google.common.collect.testing.features.SetFeature; -import junit.framework.Test; -import junit.framework.TestSuite; -import org.jhotdraw8.collection.MutableVectorSet; - -import java.lang.reflect.Method; -import java.util.Collection; -import java.util.Collections; -import java.util.Set; - -/** - * Tests {@link MutableVectorSet} with the Guava test suite. - */ -public class MutableVectorSetGuavaTests { - - public static Test suite() { - return new MutableVectorSetGuavaTests().allTests(); - } - - public Test allTests() { - TestSuite suite = new TestSuite(MutableVectorSet.class.getSimpleName()); - suite.addTest(testsForSet()); - suite.addTest(testsForReversedSet()); - return suite; - } - - public Test testsForSet() { - return SetTestSuiteBuilder.using( - new TestStringSetGenerator() { - @Override - public Set create(String[] elements) { - return new MutableVectorSet<>(MinimalCollection.of(elements)); - } - }) - .named(MutableVectorSet.class.getSimpleName()) - .withFeatures( - SetFeature.GENERAL_PURPOSE, - CollectionFeature.KNOWN_ORDER, - CollectionFeature.ALLOWS_NULL_VALUES, - CollectionFeature.ALLOWS_NULL_QUERIES, - CollectionFeature.SERIALIZABLE, - CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION, - CollectionSize.ANY) - .suppressing(suppressForSet()) - .createTestSuite(); - } - - public Test testsForReversedSet() { - return SetTestSuiteBuilder.using( - new TestStringSetGenerator() { - @Override - public Set create(String[] elements) { - return new MutableVectorSet<>(MinimalCollection.of(elements))._reversed(); - } - }) - .named(MutableVectorSet.class.getSimpleName() + "_reversed") - .withFeatures( - SetFeature.GENERAL_PURPOSE, - //CollectionFeature.KNOWN_ORDER, - CollectionFeature.ALLOWS_NULL_VALUES, - CollectionFeature.ALLOWS_NULL_QUERIES, - //CollectionFeature.SERIALIZABLE, - CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION, - CollectionSize.ANY) - .suppressing(suppressForSet()) - .createTestSuite(); - } - - protected Collection suppressForSet() { - return Collections.emptySet(); - } - - -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/VectorListGuavaTests.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/VectorListGuavaTests.java deleted file mode 100644 index 70c86a945..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/guava/VectorListGuavaTests.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * @(#)ChampSetGuavaTests.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.guava; - -import com.google.common.collect.testing.ListTestSuiteBuilder; -import com.google.common.collect.testing.MinimalCollection; -import com.google.common.collect.testing.TestStringListGenerator; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.collect.testing.features.CollectionSize; -import com.google.common.collect.testing.features.ListFeature; -import junit.framework.Test; -import junit.framework.TestSuite; -import org.jhotdraw8.collection.MutableVectorList; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.facade.MutableListFacade; - -import java.lang.reflect.Method; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -/** - * Tests {@link VectorList} with the Guava test suite. - */ - -public class VectorListGuavaTests { - - public static Test suite() { - return new VectorListGuavaTests().allTests(); - } - - public Test allTests() { - TestSuite suite = new TestSuite(MutableVectorList.class.getSimpleName()); - suite.addTest(testsForTrieList()); - return suite; - } - - public Test testsForTrieList() { - return ListTestSuiteBuilder.using( - new TestStringListGenerator() { - @Override - public List create(String[] elements) { - return new MutableListFacade<>(VectorList.copyOf(MinimalCollection.of(elements))); - } - }) - .named(MutableVectorList.class.getSimpleName()) - .withFeatures( - ListFeature.GENERAL_PURPOSE, - CollectionFeature.ALLOWS_NULL_VALUES, - CollectionFeature.ALLOWS_NULL_QUERIES, - // CollectionFeature.SERIALIZABLE, - CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION, - CollectionSize.ANY) - .suppressing(suppressForTrieSet()) - .createTestSuite(); - } - - protected Collection suppressForTrieSet() { - return Collections.emptySet(); - } - -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ZipperTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ZipperTest.java deleted file mode 100644 index 740b85401..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/immutable/ZipperTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.jhotdraw8.collection.immutable; - -import org.jhotdraw8.collection.VectorList; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - - -public class ZipperTest { - @Test - public void shouldZipList() { - VectorList actual = VectorList.of("a", "b", "c"); - actual = actual.transformed().by(ZipTransformer.zipList((a, b) -> a + b)); - VectorList expected = VectorList.of("ab", "c"); - assertEquals(expected, actual); - } - - @Test - public void shouldZipListInReverse() { - VectorList actual = VectorList.of("a", "b", "c"); - actual = actual.transformed().by(ZipTransformer.zipListInReverse((a, b) -> a + b)); - VectorList expected = VectorList.of("a", "bc"); - assertEquals(expected, actual); - } - - @Test - public void shouldZipListInReverseUntilSizeIsOne() { - VectorList actual = VectorList.of("a", "b", "c", "d", "e", "f", "g"); - while (actual.size() > 1) { - actual = actual.transformed().by(ZipTransformer.zipListInReverse((a, b) -> a + b)); - } - VectorList expected = VectorList.of("abcdefg"); - assertEquals(expected, actual); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/ChampMapJmh.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/ChampMapJmh.java deleted file mode 100644 index b9f56fdd7..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/ChampMapJmh.java +++ /dev/null @@ -1,216 +0,0 @@ -package org.jhotdraw8.collection.jmh; - -import org.jhotdraw8.collection.ChampMap; -import org.jhotdraw8.collection.enumerator.BareEnumerator; -import org.jhotdraw8.collection.enumerator.SpliteratorEnumeratorWrapper; -import org.openjdk.jmh.annotations.Benchmark; -import org.openjdk.jmh.annotations.BenchmarkMode; -import org.openjdk.jmh.annotations.Fork; -import org.openjdk.jmh.annotations.Measurement; -import org.openjdk.jmh.annotations.Mode; -import org.openjdk.jmh.annotations.OutputTimeUnit; -import org.openjdk.jmh.annotations.Param; -import org.openjdk.jmh.annotations.Scope; -import org.openjdk.jmh.annotations.Setup; -import org.openjdk.jmh.annotations.State; -import org.openjdk.jmh.annotations.Warmup; - -import java.util.Map; -import java.util.concurrent.TimeUnit; - -/** - *
- * # JMH version: 1.36
- * # VM version: JDK 17, OpenJDK 64-Bit Server VM, 17+35-2724
- * # Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
- *
- * Benchmark                           (mask)    (size)  Mode  Cnt           Score   Error  Units
- * ChampMapJmh.mContainsFound             -65        10  avgt                8.135          ns/op
- * ChampMapJmh.mContainsFound             -65      1000  avgt               16.979          ns/op
- * ChampMapJmh.mContainsFound             -65    100000  avgt               57.673          ns/op
- * ChampMapJmh.mContainsFound             -65  10000000  avgt              260.768          ns/op
- * ChampMapJmh.mContainsNotFound          -65        10  avgt                6.709          ns/op
- * ChampMapJmh.mContainsNotFound          -65      1000  avgt               16.938          ns/op
- * ChampMapJmh.mContainsNotFound          -65    100000  avgt               59.807          ns/op
- * ChampMapJmh.mContainsNotFound          -65  10000000  avgt              262.135          ns/op
- * ChampMapJmh.mCopyOf                    -65        10  avgt              477.720          ns/op
- * ChampMapJmh.mCopyOf                    -65      1000  avgt           104483.164          ns/op
- * ChampMapJmh.mCopyOf                    -65    100000  avgt         16088857.957          ns/op
- * ChampMapJmh.mCopyOf                    -65  10000000  avgt       4313203539.000          ns/op
- * ChampMapJmh.mCopyOnyByOne              -65        10  avgt              318.818          ns/op
- * ChampMapJmh.mCopyOnyByOne              -65      1000  avgt            93286.049          ns/op
- * ChampMapJmh.mCopyOnyByOne              -65    100000  avgt         24708346.472          ns/op
- * ChampMapJmh.mCopyOnyByOne              -65  10000000  avgt       5741029507.000          ns/op
- * ChampMapJmh.mHead                      -65        10  avgt                9.839          ns/op
- * ChampMapJmh.mHead                      -65      1000  avgt               12.357          ns/op
- * ChampMapJmh.mHead                      -65    100000  avgt               18.366          ns/op
- * ChampMapJmh.mHead                      -65  10000000  avgt               29.306          ns/op
- * ChampMapJmh.mIterate                   -65        10  avgt              36.719          ns/op
- * ChampMapJmh.mIterate                   -65      1000  avgt             5458.660          ns/op
- * ChampMapJmh.mIterate                   -65    100000  avgt          3442606.147          ns/op
- * ChampMapJmh.mIterate                   -65  10000000  avgt        465335856.500          ns/op
- * ChampMapJmh.mIterateEnumerator         -65        10  avgt               18.694          ns/op
- * ChampMapJmh.mIterateEnumerator         -65      1000  avgt             6114.990          ns/op
- * ChampMapJmh.mIterateEnumerator         -65    100000  avgt          3622574.584          ns/op
- * ChampMapJmh.mIterateEnumerator         -65  10000000  avgt        497013579.095          ns/op
- * ChampMapJmh.mPut                       -65        10  avgt               30.346          ns/op
- * ChampMapJmh.mPut                       -65      1000  avgt               71.152          ns/op
- * ChampMapJmh.mPut                       -65    100000  avgt              151.594          ns/op
- * ChampMapJmh.mPut                       -65  10000000  avgt              657.308          ns/op
- * ChampMapJmh.mRemoveAll                 -65        10  avgt              359.833          ns/op
- * ChampMapJmh.mRemoveAll                 -65      1000  avgt           116705.160          ns/op
- * ChampMapJmh.mRemoveAll                 -65    100000  avgt         23554134.598          ns/op
- * ChampMapJmh.mRemoveAll                 -65  10000000  avgt       4903560584.333          ns/op
- * ChampMapJmh.mRemoveOneByOne            -65        10  avgt              326.347          ns/op
- * ChampMapJmh.mRemoveOneByOne            -65      1000  avgt            97945.848          ns/op
- * ChampMapJmh.mRemoveOneByOne            -65    100000  avgt         26517407.447          ns/op
- * ChampMapJmh.mRemoveOneByOne            -65  10000000  avgt       7446733856.500          ns/op
- * ChampMapJmh.mRemoveThenAdd             -65        10  avgt               68.077          ns/op
- * ChampMapJmh.mRemoveThenAdd             -65      1000  avgt              185.762          ns/op
- * ChampMapJmh.mRemoveThenAdd             -65    100000  avgt              328.524          ns/op
- * ChampMapJmh.mRemoveThenAdd             -65  10000000  avgt              823.737          ns/op
- * ChampMapJmh.mRetainAllAllRetained      -65        10  avgt              131.176          ns/op
- * ChampMapJmh.mRetainAllAllRetained      -65      1000  avgt            18451.559          ns/op
- * ChampMapJmh.mRetainAllAllRetained      -65    100000  avgt          5670748.948          ns/op
- * ChampMapJmh.mRetainAllAllRetained      -65  10000000  avgt       1811336749.167          ns/op
- * ChampMapJmh.mRetainAllNoneRetained     -65        10  avgt              115.168          ns/op
- * ChampMapJmh.mRetainAllNoneRetained     -65      1000  avgt            17648.255          ns/op
- * ChampMapJmh.mRetainAllNoneRetained     -65    100000  avgt          5040221.174          ns/op
- * ChampMapJmh.mRetainAllNoneRetained     -65  10000000  avgt       1759449465.000          ns/op
- * ChampMapJmh.mTail                      -65        10  avgt               29.769          ns/op
- * ChampMapJmh.mTail                      -65      1000  avgt               50.720          ns/op
- * ChampMapJmh.mTail                      -65    100000  avgt               92.446          ns/op
- * ChampMapJmh.mTail                      -65  10000000  avgt              110.721          ns/op
- *
- * Process finished with exit code 0
- * 
- */ -@State(Scope.Benchmark) -@Measurement(iterations = 2) -@Warmup(iterations = 2) -@Fork(value = 1, jvmArgsAppend = {"-ea", "-Xmx28g"}) -@OutputTimeUnit(TimeUnit.NANOSECONDS) -@BenchmarkMode(Mode.AverageTime) -public class ChampMapJmh { - @Param({/*"10", "1000",*/ "100000"/*, "10000000"*/}) - private int size; - - @Param({"-65"}) - private int mask; - - private BenchmarkData data; - private ChampMap mapA; - - @Setup - public void setup() { - data = new BenchmarkData(size, mask); - mapA = ChampMap.of(); - for (Key key : data.setA) { - mapA = mapA.put(key, Boolean.TRUE); - } - } - - - @Benchmark - public int mIterate() { - int sum = 0; - for (Key k : mapA.readOnlyKeySet()) { - sum += k.value; - } - return sum; - } - - @Benchmark - public int mIterateEnumerator() { - int sum = 0; - for (BareEnumerator> i = new SpliteratorEnumeratorWrapper<>(mapA.spliterator()); i.moveNext(); ) { - sum += i.current().getKey().value; - } - return sum; - } -/* - @Benchmark - public ChampMap mRemoveThenAdd() { - Key key = data.nextKeyInA(); - return mapA.remove(key).put(key, Boolean.TRUE); - } - - @Benchmark - public ChampMap mPut() { - Key key = data.nextKeyInA(); - return mapA.put(key, Boolean.FALSE); - } - - @Benchmark - public ChampMap mCopyOf() { - return ChampMap.copyOf(data.mapA); - } - - @Benchmark - public ChampMap mCopyOnyByOne() { - ChampMap set = ChampMap.of(); - for (Key key : data.listA) { - set = set.put(key, Boolean.FALSE); - } - assert set.size() == data.listA.size(); - return set; - } - - @Benchmark - public boolean mContainsFound() { - Key key = data.nextKeyInA(); - return mapA.containsKey(key); - } - - @Benchmark - public boolean mContainsNotFound() { - Key key = data.nextKeyInB(); - return mapA.containsKey(key); - } - - @Benchmark - public Key mHead() { - return mapA.iterator().next().getKey(); - } - - @Benchmark - public ChampMap mTail() { - return mapA.remove(mapA.iterator().next().getKey()); - } - - @Benchmark - public ChampMap mRemoveOneByOne() { - var map = mapA; - for (var e : data.listA) { - map = map.remove(e); - } - if (!map.isEmpty()) throw new AssertionError("map: " + map); - return map; - } - - - @Benchmark - public ChampMap mRemoveAll() { - var updated = mapA.removeAll(data.setA); - assert updated.isEmpty(); - return updated; - } - - @Benchmark - public ChampMap mRetainAllNoneRetained() { - var set = mapA; - var updated = set.retainAll(data.setB); - assert updated.isEmpty(); - return updated; - } - - @Benchmark - public ChampMap mRetainAllAllRetained() { - var set = mapA; - var updated = set.retainAll(data.setA); - assert updated == mapA; - return updated; - } - - */ -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/ChampSetJmh.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/ChampSetJmh.java deleted file mode 100644 index e52a505a4..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/ChampSetJmh.java +++ /dev/null @@ -1,250 +0,0 @@ -package org.jhotdraw8.collection.jmh; - - -import org.jhotdraw8.collection.ChampSet; -import org.openjdk.jmh.annotations.*; - -import java.util.concurrent.TimeUnit; - -/** - *
- * # JMH version: 1.36
- * # VM version: JDK 17, OpenJDK 64-Bit Server VM, 17+35-2724
- * # Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
- * Benchmark                          (mask)  (size)  Mode  Cnt        Score   Error  Units
- * ChampSetJmh.mIterate                  -65  100000  avgt        844158.536          ns/op
- * ChampSetJmh.mIterateEnumerator        -65  100000  avgt       1244576.380          ns/op
- * 
- *
- * # JMH version: 1.36
- * # VM version: JDK 17, OpenJDK 64-Bit Server VM, 17+35-2724
- * # Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
- *
- * Benchmark                                            (mask)    (size)  Mode  Cnt           Score   Error  Units
- * ChampSetJmh.mContainsFound                              -65        10  avgt                6.531          ns/op
- * ChampSetJmh.mContainsFound                              -65      1000  avgt               19.339          ns/op
- * ChampSetJmh.mContainsFound                              -65    100000  avgt               47.582          ns/op
- * ChampSetJmh.mContainsFound                              -65  10000000  avgt              254.669          ns/op
- * ChampSetJmh.mContainsNotFound                           -65        10  avgt                6.406          ns/op
- * ChampSetJmh.mContainsNotFound                           -65      1000  avgt               18.927          ns/op
- * ChampSetJmh.mContainsNotFound                           -65    100000  avgt               46.014          ns/op
- * ChampSetJmh.mContainsNotFound                           -65  10000000  avgt              254.937          ns/op
- * ChampSetJmh.mCopyOf                                     -65        10  avgt              317.836          ns/op
- * ChampSetJmh.mCopyOf                                     -65      1000  avgt            74404.258          ns/op
- * ChampSetJmh.mCopyOf                                     -65    100000  avgt         14735906.381          ns/op
- * ChampSetJmh.mCopyOf                                     -65  10000000  avgt       4359554195.667          ns/op
- * ChampSetJmh.mCopyOnyByOne                               -65        10  avgt              378.281          ns/op
- * ChampSetJmh.mCopyOnyByOne                               -65      1000  avgt            97965.052          ns/op
- * ChampSetJmh.mCopyOnyByOne                               -65    100000  avgt         21545690.991          ns/op
- * ChampSetJmh.mCopyOnyByOne                               -65  10000000  avgt       6506215978.500          ns/op
- * ChampSetJmh.mHead                                       -65        10  avgt                9.537          ns/op
- * ChampSetJmh.mHead                                       -65      1000  avgt               11.642          ns/op
- * ChampSetJmh.mHead                                       -65    100000  avgt               21.940          ns/op
- * ChampSetJmh.mHead                                       -65  10000000  avgt               27.751          ns/op
- * ChampSetJmh.mIterate                                    -65        10  avgt               17.048          ns/op
- * ChampSetJmh.mIterate                                    -65      1000  avgt             3685.048          ns/op
- * ChampSetJmh.mIterate                                    -65    100000  avgt           703833.573          ns/op
- * ChampSetJmh.mIterate                                    -65  10000000  avgt        286645121.114          ns/op
- * ChampSetJmh.mIterateEnumerator                          -65        10  avgt               15.061          ns/op
- * ChampSetJmh.mIterateEnumerator                          -65      1000  avgt             5328.946          ns/op
- * ChampSetJmh.mIterateEnumerator                          -65    100000  avgt          1153913.409          ns/op
- * ChampSetJmh.mIterateEnumerator                          -65  10000000  avgt        355126769.310          ns/op
- * ChampSetJmh.mIterateEnumeratorOld                       -65        10  avgt               19.619          ns/op
- * ChampSetJmh.mIterateEnumeratorOld                       -65      1000  avgt             6437.539          ns/op
- * ChampSetJmh.mIterateEnumeratorOld                       -65    100000  avgt          1246307.863          ns/op
- * ChampSetJmh.mIterateEnumeratorOld                       -65  10000000  avgt        385883555.654          ns/op
- * ChampSetJmh.mRemoveAllFromDifferentType                 -65        10  avgt              348.410          ns/op
- * ChampSetJmh.mRemoveAllFromDifferentType                 -65      1000  avgt            90834.499          ns/op
- * ChampSetJmh.mRemoveAllFromDifferentType                 -65    100000  avgt         16550150.296          ns/op
- * ChampSetJmh.mRemoveAllFromDifferentType                 -65  10000000  avgt       3790235960.000          ns/op
- * ChampSetJmh.mRemoveAllFromSameType                      -65        10  avgt               80.781          ns/op
- * ChampSetJmh.mRemoveAllFromSameType                      -65      1000  avgt            11948.630          ns/op
- * ChampSetJmh.mRemoveAllFromSameType                      -65    100000  avgt          1400446.241          ns/op
- * ChampSetJmh.mRemoveAllFromSameType                      -65  10000000  avgt        247237967.220          ns/op
- * ChampSetJmh.mRemoveOneByOne                             -65        10  avgt              294.905          ns/op
- * ChampSetJmh.mRemoveOneByOne                             -65      1000  avgt           105479.850          ns/op
- * ChampSetJmh.mRemoveOneByOne                             -65    100000  avgt         23467126.398          ns/op
- * ChampSetJmh.mRemoveOneByOne                             -65  10000000  avgt       6457404845.500          ns/op
- * ChampSetJmh.mRemoveThenAdd                              -65        10  avgt               83.087          ns/op
- * ChampSetJmh.mRemoveThenAdd                              -65      1000  avgt              192.916          ns/op
- * ChampSetJmh.mRemoveThenAdd                              -65    100000  avgt              315.212          ns/op
- * ChampSetJmh.mRemoveThenAdd                              -65  10000000  avgt              837.040          ns/op
- * ChampSetJmh.mRetainAllFromDifferentTypeAllRetained      -65        10  avgt              134.594          ns/op
- * ChampSetJmh.mRetainAllFromDifferentTypeAllRetained      -65      1000  avgt            16371.598          ns/op
- * ChampSetJmh.mRetainAllFromDifferentTypeAllRetained      -65    100000  avgt          4563910.792          ns/op
- * ChampSetJmh.mRetainAllFromDifferentTypeAllRetained      -65  10000000  avgt       1718482181.833          ns/op
- * ChampSetJmh.mRetainAllFromDifferentTypeNoneRetained     -65        10  avgt              117.174          ns/op
- * ChampSetJmh.mRetainAllFromDifferentTypeNoneRetained     -65      1000  avgt            17332.768          ns/op
- * ChampSetJmh.mRetainAllFromDifferentTypeNoneRetained     -65    100000  avgt          3382914.628          ns/op
- * ChampSetJmh.mRetainAllFromDifferentTypeNoneRetained     -65  10000000  avgt       1622840678.000          ns/op
- * ChampSetJmh.mRetainAllFromSameTypeAllRetained           -65        10  avgt              102.645          ns/op
- * ChampSetJmh.mRetainAllFromSameTypeAllRetained           -65      1000  avgt            14075.248          ns/op
- * ChampSetJmh.mRetainAllFromSameTypeAllRetained           -65    100000  avgt          1496210.664          ns/op
- * ChampSetJmh.mRetainAllFromSameTypeAllRetained           -65  10000000  avgt        246502737.683          ns/op
- * ChampSetJmh.mRetainAllFromSameTypeNoneRetained          -65        10  avgt               77.052          ns/op
- * ChampSetJmh.mRetainAllFromSameTypeNoneRetained          -65      1000  avgt             8153.361          ns/op
- * ChampSetJmh.mRetainAllFromSameTypeNoneRetained          -65    100000  avgt          1379481.006          ns/op
- * ChampSetJmh.mRetainAllFromSameTypeNoneRetained          -65  10000000  avgt        347464112.690          ns/op
- * ChampSetJmh.mTail                                       -65        10  avgt               20.613          ns/op
- * ChampSetJmh.mTail                                       -65      1000  avgt               48.886          ns/op
- * ChampSetJmh.mTail                                       -65    100000  avgt               88.017          ns/op
- * ChampSetJmh.mTail                                       -65  10000000  avgt              112.837          ns/op
- * 
- */ -@State(Scope.Benchmark) -@Measurement(iterations = 2) -@Warmup(iterations = 1) -@Fork(value = 1, jvmArgsAppend = {"-ea", "-Xmx28g",}) -@OutputTimeUnit(TimeUnit.NANOSECONDS) -@BenchmarkMode(Mode.AverageTime) -public class ChampSetJmh { - @Param({/*"10", "1000",*/ /*"100000",*/ "100000"}) - private int size; - - @Param({"-65"}) - private int mask; - - private BenchmarkData data; - private ChampSet setA; - private ChampSet setB; - private ChampSet setAA; - - @Setup - public void setup() { - data = new BenchmarkData(size, mask); - setA = ChampSet.copyOf(data.setA); - setB = ChampSet.copyOf(data.listB); - setAA = ChampSet.copyOf(data.listA); - assert setA.size() == size; - assert setB.size() == size; - assert setAA.size() == size; - } - - - @Benchmark - public ChampSet mCopyOf() { - ChampSet set = ChampSet.copyOf(data.listA); - assert set.size() == data.listA.size(); - return set; - } - - - @Benchmark - public ChampSet mCopyOnyByOne() { - ChampSet set = ChampSet.of(); - for (Key key : data.listA) { - set = set.add(key); - } - assert set.size() == data.listA.size(); - return set; - } -/* - @Benchmark - public ChampSet mRemoveOneByOne() { - ChampSet set = setA; - for (Key key : data.listA) { - set = set.remove(key); - } - assert set.isEmpty(); - return set; - } - - @Benchmark - public ChampSet mRemoveAllFromDifferentType() { - ChampSet set = setA; - ChampSet updated = set.removeAll(data.setA); - assert updated.isEmpty(); - return updated; - } - - @Benchmark - public ChampSet mRemoveAllFromSameType() { - ChampSet set = setA; - ChampSet updated = set.removeAll(setAA); - assert updated.isEmpty(); - return updated; - } - - - @Benchmark - public ChampSet mRetainAllFromDifferentTypeAllRetained() { - ChampSet set = setA; - ChampSet updated = set.retainAll(data.setA); - assert updated == setA; - return updated; - } - - @Benchmark - public ChampSet mRetainAllFromDifferentTypeNoneRetained() { - ChampSet set = setA; - ChampSet updated = set.retainAll(data.setB); - assert updated.isEmpty(); - return updated; - } - - @Benchmark - public ChampSet mRetainAllFromSameTypeAllRetained() { - ChampSet set = setA; - ChampSet updated = set.retainAll(setAA); - assert updated == setA; - return updated; - } - - - @Benchmark - public ChampSet mRetainAllFromSameTypeNoneRetained() { - ChampSet set = setA; - ChampSet updated = set.retainAll(setB); - assert updated.isEmpty(); - return updated; - } - - @Benchmark - public int mIterate() { - int sum = 0; - for (Key k : setA) { - sum += k.value; - } - return sum; - } - - @Benchmark - public int mIterateEnumerator() { - int sum = 0; - for (var i = new SpliteratorEnumeratorWrapper<>(setA.spliterator()); i.moveNext(); ) { - sum += i.current().value; - } - return sum; - } - - @Benchmark - public Key mHead() { - return setA.iterator().next(); - } - - - @Benchmark - public ChampSet mRemoveThenAdd() { - Key key = data.nextKeyInA(); - return setA.remove(key).add(key); - } - - - @Benchmark - public ChampSet mTail() { - return setA.remove(setA.iterator().next()); - } - - @Benchmark - public boolean mContainsFound() { - Key key = data.nextKeyInA(); - return setA.contains(key); - } - - @Benchmark - public boolean mContainsNotFound() { - Key key = data.nextKeyInB(); - return setA.contains(key); - } -*/ -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/MutableVectorListJmh.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/MutableVectorListJmh.java deleted file mode 100644 index e94043ceb..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/MutableVectorListJmh.java +++ /dev/null @@ -1,204 +0,0 @@ -package org.jhotdraw8.collection.jmh; - -import org.jhotdraw8.collection.MutableVectorList; -import org.openjdk.jmh.annotations.Benchmark; -import org.openjdk.jmh.annotations.BenchmarkMode; -import org.openjdk.jmh.annotations.Fork; -import org.openjdk.jmh.annotations.Measurement; -import org.openjdk.jmh.annotations.Mode; -import org.openjdk.jmh.annotations.OutputTimeUnit; -import org.openjdk.jmh.annotations.Param; -import org.openjdk.jmh.annotations.Scope; -import org.openjdk.jmh.annotations.Setup; -import org.openjdk.jmh.annotations.State; -import org.openjdk.jmh.annotations.Warmup; - -import java.math.BigInteger; -import java.util.Iterator; -import java.util.concurrent.TimeUnit; - -/** - *
- * # JMH version: 1.36
- * # VM version: JDK 17, OpenJDK 64-Bit Server VM, 17+35-2724
- * # Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
- *
- * Benchmark                                (size)  Mode  Cnt          Score   Error  Units
- * mAddAll                 10  avgt              77.242          ns/op
- * mAddAll               1000  avgt            3709.905          ns/op
- * mAddAll            1000000  avgt        11080872.333          ns/op
- * mAddFirst               10  avgt              38.269          ns/op
- * mAddFirst             1000  avgt              53.137          ns/op
- * mAddFirst          1000000  avgt             146.635          ns/op
- * mAddLast                10  avgt              19.775          ns/op
- * mAddLast              1000  avgt              31.118          ns/op
- * mAddLast           1000000  avgt             119.156          ns/op
- * mAddOneByOne            10  avgt             182.656          ns/op
- * mAddOneByOne          1000  avgt           40228.752          ns/op
- * mAddOneByOne       1000000  avgt       135684419.365          ns/op
- * mContainsNotFound       10  avgt              11.607          ns/op
- * mContainsNotFound     1000  avgt            1253.487          ns/op
- * mContainsNotFound  1000000  avgt         8327974.089          ns/op
- * mGet                    10  avgt               4.193          ns/op
- * mGet                  1000  avgt               7.513          ns/op
- * mGet               1000000  avgt              88.663          ns/op
- * mHead                   10  avgt               2.158          ns/op
- * mHead                 1000  avgt               2.660          ns/op
- * mHead              1000000  avgt               5.910          ns/op
- * mIterate                10  avgt              12.823          ns/op
- * mIterate              1000  avgt            2088.217          ns/op
- * mIterate           1000000  avgt        22462897.942          ns/op ?
- * mRemoveAtIndex          10  avgt              44.574          ns/op
- * mRemoveAtIndex        1000  avgt            2872.760          ns/op
- * mRemoveAtIndex     1000000  avgt         3297735.069          ns/op
- * mRemoveLast             10  avgt              15.569          ns/op
- * mRemoveLast           1000  avgt              17.339          ns/op
- * mRemoveLast        1000000  avgt              19.416          ns/op
- * mReversedIterate        10  avgt              10.292          ns/op
- * mReversedIterate      1000  avgt            1915.076          ns/op
- * mReversedIterate   1000000  avgt        22342912.355          ns/op ?
- * mSet                    10  avgt              24.423          ns/op
- * mSet                  1000  avgt              41.456          ns/op
- * mSet               1000000  avgt             237.644          ns/op
- * mTail                   10  avgt              16.312          ns/op
- * mTail                 1000  avgt              16.619          ns/op
- * mTail              1000000  avgt              20.296          ns/op
- *
- * Process finished with exit code 0
- *
- * Process finished with exit code 0
- */
-@State(Scope.Benchmark)
-@Measurement(iterations = 1)
-@Warmup(iterations = 1)
-@Fork(value = 1, jvmArgsAppend = {"-Xmx28g"})
-@OutputTimeUnit(TimeUnit.NANOSECONDS)
-@BenchmarkMode(Mode.AverageTime)
-public class MutableVectorListJmh {
-    @Param({"10", "1000", "1000000"})
-    private int size;
-
-    private int mask = -65;
-
-    private BenchmarkData data;
-    private MutableVectorList listA;
-
-    private int index;
-
-    @Setup
-    public void setup() {
-        data = new BenchmarkData(size, mask);
-        listA = new MutableVectorList();
-        for (Key key : data.setA) {
-            listA.add(key);
-        }
-        index = Math.min(listA.size() - 1, BigInteger.valueOf(listA.size() / 2).nextProbablePrime().intValue());
-    }
-
-
-    @Benchmark
-    public MutableVectorList mAddAll() {
-        return new MutableVectorList<>(data.setA);
-    }
-
-    @Benchmark
-    public MutableVectorList mAddOneByOne() {
-        MutableVectorList set = new MutableVectorList<>();
-        for (Key key : data.listA) {
-            set.add(key);
-        }
-        return set;
-    }
-
-    //@Benchmark
-    public MutableVectorList mRemoveOneByOne() {
-        var map = listA.clone();
-        for (var e : data.listA) {
-            map.remove(e);
-        }
-        if (!map.isEmpty()) throw new AssertionError("map: " + map);
-        return map;
-    }
-
-    //@Benchmark
-    public boolean mRemoveAll() {
-        MutableVectorList set = listA.clone();
-        return set.removeAll(data.listA);
-    }
-
-    @Benchmark
-    public int mIterate() {
-        int sum = 0;
-        for (Iterator i = listA.iterator(); i.hasNext(); ) {
-            sum += i.next().value;
-        }
-        return sum;
-    }
-
-    @Benchmark
-    public int mReversedIterate() {
-        int sum = 0;
-        for (int i = listA.size() - 1; i >= 0; i--) {
-            sum += listA.get(i).value;
-        }
-        return sum;
-    }
-
-    @Benchmark
-    public Key mTail() {
-        return listA.clone().remove(0);
-    }
-
-    @Benchmark
-    public boolean mAddLast() {
-        Key key = data.nextKeyInB();
-        return listA.clone().add(key);
-    }
-
-    @Benchmark
-    public int mAddFirst() {
-        Key key = data.nextKeyInB();
-        MutableVectorList clone = listA.clone();
-        clone.addFirst(key);
-        return clone.size();
-    }
-
-
-    @Benchmark
-    public Key mRemoveLast() {
-        MutableVectorList clone = listA.clone();
-        return clone.remove(clone.size() - 1);
-    }
-
-    @Benchmark
-    public Key mRemoveAtIndex() {
-        MutableVectorList clone = listA.clone();
-        return clone.remove(index);
-    }
-
-    @Benchmark
-    public Key mGet() {
-        int index = data.nextIndexInA();
-        return listA.get(index);
-    }
-
-    @Benchmark
-    public boolean mContainsNotFound() {
-        Key key = data.nextKeyInB();
-        return listA.contains(key);
-    }
-
-    @Benchmark
-    public Key mHead() {
-        return listA.get(0);
-    }
-
-    @Benchmark
-    public Key mSet() {
-        int index = data.nextIndexInA();
-        Key key = data.nextKeyInB();
-        return listA.set(index, key);
-    }
-
-
-}
diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/VectorListJmh.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/VectorListJmh.java
deleted file mode 100644
index 8781f1288..000000000
--- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/VectorListJmh.java
+++ /dev/null
@@ -1,204 +0,0 @@
-package org.jhotdraw8.collection.jmh;
-
-import org.jhotdraw8.collection.VectorList;
-import org.openjdk.jmh.annotations.Benchmark;
-import org.openjdk.jmh.annotations.BenchmarkMode;
-import org.openjdk.jmh.annotations.Fork;
-import org.openjdk.jmh.annotations.Measurement;
-import org.openjdk.jmh.annotations.Mode;
-import org.openjdk.jmh.annotations.OutputTimeUnit;
-import org.openjdk.jmh.annotations.Param;
-import org.openjdk.jmh.annotations.Scope;
-import org.openjdk.jmh.annotations.Setup;
-import org.openjdk.jmh.annotations.State;
-import org.openjdk.jmh.annotations.Warmup;
-
-import java.math.BigInteger;
-import java.util.concurrent.TimeUnit;
-
-/**
- * 
- * # JMH version: 1.36
- * # VM version: JDK 17, OpenJDK 64-Bit Server VM, 17+35-2724
- * # Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
- *
- * Benchmark           (size)  Mode  Cnt          Score   Error  Units
- * mAddAll                 10  avgt              52.805          ns/op
- * mAddAll               1000  avgt            3875.245          ns/op
- * mAddAll            1000000  avgt        11166047.498          ns/op
- * mAddAllArray            10  avgt              36.627          ns/op
- * mAddAllArray          1000  avgt            3831.702          ns/op
- * mAddAllArray       1000000  avgt        18233901.719          ns/op
- * mAddFirst               10  avgt              43.874          ns/op
- * mAddFirst             1000  avgt              50.507          ns/op
- * mAddFirst          1000000  avgt             140.191          ns/op
- * mAddLast                10  avgt              22.597          ns/op
- * mAddLast              1000  avgt              34.994          ns/op
- * mAddLast           1000000  avgt             127.617          ns/op
- * mAddOneByOne            10  avgt             211.522          ns/op
- * mAddOneByOne          1000  avgt           43554.723          ns/op
- * mAddOneByOne       1000000  avgt       134181586.813          ns/op
- * mContainsNotFound       10  avgt              27.532          ns/op
- * mContainsNotFound     1000  avgt            2794.591          ns/op
- * mContainsNotFound  1000000  avgt         5675693.984          ns/op
- * mGet                    10  avgt               3.691          ns/op
- * mGet                  1000  avgt               7.463          ns/op
- * mGet               1000000  avgt              86.203          ns/op
- * mHead                   10  avgt               1.747          ns/op
- * mHead                 1000  avgt               2.236          ns/op
- * mHead              1000000  avgt               5.083          ns/op
- * mIterate                10  avgt              12.636          ns/op
- * mIterate              1000  avgt            1426.097          ns/op
- * mIterate           1000000  avgt        12576434.361          ns/op
- * mRemoveAtIndex          10  avgt              40.534          ns/op
- * mRemoveAtIndex        1000  avgt            3046.037          ns/op
- * mRemoveAtIndex     1000000  avgt         3367569.843          ns/op
- * mRemoveLast             10  avgt              11.158          ns/op
- * mRemoveLast           1000  avgt              12.521          ns/op
- * mRemoveLast        1000000  avgt              10.877          ns/op
- * mReversedIterate        10  avgt              10.123          ns/op
- * mReversedIterate      1000  avgt            1841.430          ns/op
- * mReversedIterate   1000000  avgt        12294983.693          ns/op
- * mSet                    10  avgt              19.737          ns/op
- * mSet                  1000  avgt              40.689          ns/op
- * mSet               1000000  avgt             221.233          ns/op
- * mTail                   10  avgt               6.223          ns/op
- * mTail                 1000  avgt               6.307          ns/op
- * mTail              1000000  avgt               6.358          ns/op
- *
- * Process finished with exit code 0
- */
-@State(Scope.Benchmark)
-@Measurement(iterations = 1)
-@Warmup(iterations = 1)
-@Fork(value = 1, jvmArgsAppend = {"-Xmx28g"})
-@OutputTimeUnit(TimeUnit.NANOSECONDS)
-@BenchmarkMode(Mode.AverageTime)
-public class VectorListJmh {
-    @Param({"10", "1000", "1000000"})
-    private int size;
-
-    private int mask = -65;
-
-    private BenchmarkData data;
-    private VectorList listA;
-
-    private int index;
-
-    @Setup
-    public void setup() {
-        data = new BenchmarkData(size, mask);
-        listA = VectorList.of();
-        for (Key key : data.setA) {
-            listA = listA.add(key);
-        }
-        index = Math.min(listA.size() - 1, BigInteger.valueOf(listA.size() / 2).nextProbablePrime().intValue());
-    }
-
-    /*
-        @Benchmark
-        public VectorList mAddAll() {
-            return VectorList.copyOf(data.setA);
-        }        @Benchmark
-        public VectorList mAddAllArray() {
-            return VectorList.of(data.setA.toArray(new Key[0]));
-        }
-
-        @Benchmark
-        public VectorList mAddOneByOne() {
-            VectorList set = VectorList.of();
-            for (Key key : data.listA) {
-                set = set.add(key);
-            }
-            return set;
-        }
-
-        //@Benchmark
-        public VectorList mRemoveOneByOne() {
-            var map = listA;
-            for (var e : data.listA) {
-                map = map.remove(e);
-            }
-            if (!map.isEmpty()) throw new AssertionError("map: " + map);
-            return map;
-        }
-
-        //@Benchmark
-        public VectorList mRemoveAll() {
-            VectorList set = listA;
-            return set.removeAll(data.listA);
-        }
-
-        @Benchmark
-        public int mIterate() {
-            int sum = 0;
-            for (Iterator i = listA.iterator(); i.hasNext(); ) {
-                sum += i.next().value;
-            }
-            return sum;
-        }
-
-        @Benchmark
-        public int mReversedIterate() {
-            int sum = 0;
-            for (int i=listA.size()-1;i>=0;i--) {
-                sum += listA.get(i).value;
-            }
-            return sum;
-        }
-
-        @Benchmark
-        public VectorList mTail() {
-            return listA.removeAt(0);
-        }
-
-        @Benchmark
-        public VectorList mAddLast() {
-            Key key = data.nextKeyInB();
-            return (listA).add(key);
-        }
-
-        @Benchmark
-        public VectorList mAddFirst() {
-            Key key = data.nextKeyInB();
-            return (listA).add(0,key);
-        }
-*/
-
-
-    @Benchmark
-    public VectorList mRemoveLast() {
-        return listA.removeAt(listA.size() - 1);
-    }
-
-    @Benchmark
-    public VectorList mRemoveAtIndex() {
-        return listA.removeAt(index);
-    }
-/*
-    @Benchmark
-    public Key mGet() {
-        int index = data.nextIndexInA();
-        return listA.get(index);
-    }
-
-    @Benchmark
-    public boolean mContainsNotFound() {
-        Key key = data.nextKeyInB();
-        return listA.contains(key);
-    }
-
-    @Benchmark
-    public Key mHead() {
-        return listA.get(0);
-    }
-
-    @Benchmark
-    public VectorList mSet() {
-        int index = data.nextIndexInA();
-        Key key = data.nextKeyInB();
-        return listA.set(index, key);
-    }
-
- */
-}
diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/VectorMapJmh.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/VectorMapJmh.java
deleted file mode 100644
index ccac29ccf..000000000
--- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/VectorMapJmh.java
+++ /dev/null
@@ -1,214 +0,0 @@
-package org.jhotdraw8.collection.jmh;
-
-import org.jhotdraw8.collection.VectorMap;
-import org.jhotdraw8.collection.enumerator.BareEnumerator;
-import org.jhotdraw8.collection.enumerator.SpliteratorEnumeratorWrapper;
-import org.openjdk.jmh.annotations.Benchmark;
-import org.openjdk.jmh.annotations.BenchmarkMode;
-import org.openjdk.jmh.annotations.Fork;
-import org.openjdk.jmh.annotations.Measurement;
-import org.openjdk.jmh.annotations.Mode;
-import org.openjdk.jmh.annotations.OutputTimeUnit;
-import org.openjdk.jmh.annotations.Param;
-import org.openjdk.jmh.annotations.Scope;
-import org.openjdk.jmh.annotations.Setup;
-import org.openjdk.jmh.annotations.State;
-import org.openjdk.jmh.annotations.Warmup;
-
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
-/**
- * 
- * # JMH version: 1.36
- * # VM version: JDK 17, OpenJDK 64-Bit Server VM, 17+35-2724
- * # Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
- *
- * Benchmark                            (mask)    (size)  Mode  Cnt       _     Score   Error  Units
- * VectorMapJmh.mContainsFound             -65        10  avgt    2       _     5.549          ns/op
- * VectorMapJmh.mContainsFound             -65      1000  avgt    2       _    17.059          ns/op
- * VectorMapJmh.mContainsFound             -65    100000  avgt    2       _    61.928          ns/op
- * VectorMapJmh.mContainsFound             -65  10000000  avgt    2       _   286.949          ns/op
- * VectorMapJmh.mContainsNotFound          -65        10  avgt    2       _     5.334          ns/op
- * VectorMapJmh.mContainsNotFound          -65      1000  avgt    2       _    16.701          ns/op
- * VectorMapJmh.mContainsNotFound          -65    100000  avgt    2       _    67.041          ns/op
- * VectorMapJmh.mContainsNotFound          -65  10000000  avgt    2       _   274.686          ns/op
- * VectorMapJmh.mCopyOf                    -65        10  avgt    2       _   672.824          ns/op
- * VectorMapJmh.mCopyOf                    -65      1000  avgt    2       _161500.818          ns/op
- * VectorMapJmh.mCopyOf                    -65    100000  avgt    2     28_261003.919          ns/op
- * VectorMapJmh.mCopyOf                    -65  10000000  avgt    2   6517_169466.750          ns/op
- * VectorMapJmh.mCopyOnyByOne              -65        10  avgt    2       _   576.303          ns/op
- * VectorMapJmh.mCopyOnyByOne              -65      1000  avgt    2       _151587.450          ns/op
- * VectorMapJmh.mCopyOnyByOne              -65    100000  avgt    2     34_015399.609          ns/op
- * VectorMapJmh.mCopyOnyByOne              -65  10000000  avgt    2   7707_199395.500          ns/op
- * VectorMapJmh.mHead                      -65        10  avgt    2       _    13.910          ns/op
- * VectorMapJmh.mHead                      -65      1000  avgt    2       _    14.780          ns/op
- * VectorMapJmh.mHead                      -65    100000  avgt    2       _    18.737          ns/op
- * VectorMapJmh.mHead                      -65  10000000  avgt    2       _    19.569          ns/op
- * VectorMapJmh.mIterate                   -65        10  avgt    2       _   128.971          ns/op
- * VectorMapJmh.mIterate                   -65      1000  avgt    2       _ 10397.361          ns/op
- * VectorMapJmh.mIterate                   -65    100000  avgt    2      1_773507.559          ns/op
- * VectorMapJmh.mIterate                   -65  10000000  avgt    2    593_683870.912          ns/op
- * VectorMapJmh.mIterateEnumerator         -65        10  avgt    2       _    52.463          ns/op
- * VectorMapJmh.mIterateEnumerator         -65      1000  avgt    2       _  4473.126          ns/op
- * VectorMapJmh.mIterateEnumerator         -65    100000  avgt    2      1_546238.488          ns/op
- * VectorMapJmh.mIterateEnumerator         -65  10000000  avgt    2    391_293625.519          ns/op
- * VectorMapJmh.mPut                       -65        10  avgt    2       _    39.164          ns/op
- * VectorMapJmh.mPut                       -65      1000  avgt    2       _   119.436          ns/op
- * VectorMapJmh.mPut                       -65    100000  avgt    2       _   278.867          ns/op
- * VectorMapJmh.mPut                       -65  10000000  avgt    2       _   757.197          ns/op
- * VectorMapJmh.mRemoveAll                 -65        10  avgt    2       _   569.006          ns/op
- * VectorMapJmh.mRemoveAll                 -65      1000  avgt    2       _151818.984          ns/op
- * VectorMapJmh.mRemoveAll                 -65    100000  avgt    2     26_904156.302          ns/op
- * VectorMapJmh.mRemoveAll                 -65  10000000  avgt    2   5644_066816.250          ns/op
- * VectorMapJmh.mRemoveOneByOne            -65        10  avgt    2       _   955.478          ns/op
- * VectorMapJmh.mRemoveOneByOne            -65      1000  avgt    2       _326388.382          ns/op
- * VectorMapJmh.mRemoveOneByOne            -65    100000  avgt    2     81_476235.880          ns/op
- * VectorMapJmh.mRemoveOneByOne            -65  10000000  avgt    2  17537_430880.000          ns/op
- * VectorMapJmh.mRemoveThenAdd             -65        10  avgt    2       _   144.023          ns/op
- * VectorMapJmh.mRemoveThenAdd             -65      1000  avgt    2       _   304.386          ns/op
- * VectorMapJmh.mRemoveThenAdd             -65    100000  avgt    2       _   553.679          ns/op
- * VectorMapJmh.mRemoveThenAdd             -65  10000000  avgt    2       _  1189.360          ns/op
- * VectorMapJmh.mRetainAllAllRetained      -65        10  avgt    2       _   269.038          ns/op
- * VectorMapJmh.mRetainAllAllRetained      -65      1000  avgt    2       _ 25698.404          ns/op
- * VectorMapJmh.mRetainAllAllRetained      -65    100000  avgt    2      3_347146.065          ns/op
- * VectorMapJmh.mRetainAllAllRetained      -65  10000000  avgt    2   1079_375404.044          ns/op
- * VectorMapJmh.mRetainAllNoneRetained     -65        10  avgt    2       _   930.607          ns/op
- * VectorMapJmh.mRetainAllNoneRetained     -65      1000  avgt    2       _177402.593          ns/op
- * VectorMapJmh.mRetainAllNoneRetained     -65    100000  avgt    2     33_670087.419          ns/op
- * VectorMapJmh.mRetainAllNoneRetained     -65  10000000  avgt    2   6143_866016.000          ns/op
- * VectorMapJmh.mTail                      -65        10  avgt    2       _    51.236          ns/op
- * VectorMapJmh.mTail                      -65      1000  avgt    2       _    87.100          ns/op
- * VectorMapJmh.mTail                      -65    100000  avgt    2       _   137.688          ns/op
- * VectorMapJmh.mTail                      -65  10000000  avgt    2       _   179.967          ns/op
- *
- * Process finished with exit code 0
- * 
- */ -@State(Scope.Benchmark) -@Measurement(iterations = 2) -@Warmup(iterations = 2) -@Fork(value = 1, jvmArgsAppend = {"-ea", "-Xmx28g"}) -@OutputTimeUnit(TimeUnit.NANOSECONDS) -@BenchmarkMode(Mode.AverageTime) -public class VectorMapJmh { - @Param({"10", "1000", "100000", "10000000"}) - private int size; - - private int mask = -65; - - private BenchmarkData data; - private VectorMap mapA; - - @Setup - public void setup() { - data = new BenchmarkData(size, mask); - mapA = VectorMap.of(); - for (Key key : data.setA) { - mapA = mapA.put(key, Boolean.TRUE); - } - } - - @Benchmark - public int mIterate() { - int sum = 0; - for (Key k : mapA.readOnlyKeySet()) { - sum += k.value; - } - return sum; - } - - @Benchmark - public int mIterateEnumerator() { - int sum = 0; - for (BareEnumerator> i = new SpliteratorEnumeratorWrapper<>(mapA.spliterator()); i.moveNext(); ) { - sum += i.current().getKey().value; - } - return sum; - } - - @Benchmark - public VectorMap mRemoveThenAdd() { - Key key = data.nextKeyInA(); - return mapA.remove(key).put(key, Boolean.TRUE); - } - - @Benchmark - public VectorMap mPut() { - Key key = data.nextKeyInA(); - return mapA.put(key, Boolean.FALSE); - } - - @Benchmark - public VectorMap mCopyOf() { - return VectorMap.copyOf(data.mapA); - } - - @Benchmark - public VectorMap mCopyOnyByOne() { - VectorMap set = VectorMap.of(); - for (Key key : data.listA) { - set = set.put(key, Boolean.FALSE); - } - assert set.size() == data.listA.size(); - return set; - } - - @Benchmark - public boolean mContainsFound() { - Key key = data.nextKeyInA(); - return mapA.containsKey(key); - } - - @Benchmark - public boolean mContainsNotFound() { - Key key = data.nextKeyInB(); - return mapA.containsKey(key); - } - - @Benchmark - public Key mHead() { - return mapA.iterator().next().getKey(); - } - - @Benchmark - public VectorMap mTail() { - return mapA.remove(mapA.iterator().next().getKey()); - } - - @Benchmark - public VectorMap mRemoveOneByOne() { - var map = mapA; - for (var e : data.listA) { - map = map.remove(e); - } - if (!map.isEmpty()) throw new AssertionError("map: " + map); - return map; - } - - - @Benchmark - public VectorMap mRemoveAll() { - var updated = mapA.removeAll(data.setA); - assert updated.isEmpty(); - return updated; - } - - @Benchmark - public VectorMap mRetainAllNoneRetained() { - var set = mapA; - var updated = set.retainAll(data.setB); - assert updated.isEmpty(); - return updated; - } - - @Benchmark - public VectorMap mRetainAllAllRetained() { - var set = mapA; - var updated = set.retainAll(data.setA); - assert updated == mapA; - return updated; - } - - -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/VectorSetJmh.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/VectorSetJmh.java deleted file mode 100644 index 3a56f6794..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jmh/VectorSetJmh.java +++ /dev/null @@ -1,184 +0,0 @@ -package org.jhotdraw8.collection.jmh; - - -import org.jhotdraw8.collection.VectorSet; -import org.openjdk.jmh.annotations.Benchmark; -import org.openjdk.jmh.annotations.BenchmarkMode; -import org.openjdk.jmh.annotations.Fork; -import org.openjdk.jmh.annotations.Measurement; -import org.openjdk.jmh.annotations.Mode; -import org.openjdk.jmh.annotations.OutputTimeUnit; -import org.openjdk.jmh.annotations.Param; -import org.openjdk.jmh.annotations.Scope; -import org.openjdk.jmh.annotations.Setup; -import org.openjdk.jmh.annotations.State; -import org.openjdk.jmh.annotations.Warmup; - -import java.util.concurrent.TimeUnit; - -/** - *
- * # JMH version: 1.36
- * # VM version: JDK 17, OpenJDK 64-Bit Server VM, 17+35-2724
- * # Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
- *
- * Benchmark                                (mask)  (size)  Mode  Cnt         Score   Error  Units
- * mContainsFound                              -65  100000  avgt             74.817          ns/op
- * mContainsNotFound                           -65  100000  avgt             61.176          ns/op
- * mCopyOf                                     -65  100000  avgt       29902464.797          ns/op
- * mCopyOnyByOne                               -65  100000  avgt       35587944.904          ns/op
- * mHead                                       -65  100000  avgt             28.361          ns/op
- * mIterate                                    -65  100000  avgt        2081909.162          ns/op
- * mRemoveAllFromDifferentType                 -65  100000  avgt       26291910.722          ns/op
- * mRemoveAllFromSameType                      -65  100000  avgt       76970592.715          ns/op
- * mRemoveOneByOne                             -65  100000  avgt       88791019.823          ns/op
- * mRemoveThenAdd                              -65  100000  avgt            593.484          ns/op
- * mRetainAllFromDifferentTypeAllRetained      -65  100000  avgt        3357320.133          ns/op
- * mRetainAllFromDifferentTypeNoneRetained     -65  100000  avgt       32932049.161          ns/op
- * mRetainAllFromSameTypeAllRetained           -65  100000  avgt       10976004.332          ns/op
- * mRetainAllFromSameTypeNoneRetained          -65  100000  avgt       43730938.022          ns/op
- * mTail                                       -65  100000  avgt            144.784          ns/op
- * 
- */ -@State(Scope.Benchmark) -@Measurement(iterations = 1) -@Warmup(iterations = 1) -@Fork(value = 1, jvmArgsAppend = {"-ea", "-Xmx28g"}) -@OutputTimeUnit(TimeUnit.NANOSECONDS) -@BenchmarkMode(Mode.AverageTime) -public class VectorSetJmh { - @Param({/*"10", "1000",*/ "100000"/*, "10000000"*/}) - private int size; - - @Param({"-65"}) - private int mask; - - private BenchmarkData data; - private VectorSet setA; - private VectorSet setAA; - private VectorSet setB; - - @Setup - public void setup() { - data = new BenchmarkData(size, mask); - setA = VectorSet.copyOf(data.setA); - setB = VectorSet.copyOf(data.listB); - setAA = VectorSet.copyOf(data.listA); - } -/* - @Benchmark - public VectorSet mCopyOf() { - VectorSet set = VectorSet.copyOf(data.listA); - assert set.size() == data.listA.size(); - return set; - } - - - @Benchmark - public VectorSet mCopyOnyByOne() { - VectorSet set = VectorSet.of(); - for (Key key : data.listA) { - set = set.add(key); - } - assert set.size() == data.listA.size(); - return set; - } - - @Benchmark - public VectorSet mRemoveOneByOne() { - VectorSet set = setA; - for (Key key : data.listA) { - set = set.remove(key); - } - assert set.isEmpty(); - return set; - } -*/ - @Benchmark - public VectorSet mRemoveAllFromDifferentType() { - VectorSet set = setA; - VectorSet updated = set.removeAll(data.setA); - assert updated.isEmpty(); - return updated; - } - - @Benchmark - public VectorSet mRemoveAllFromSameType() { - VectorSet set = setA; - VectorSet updated = set.removeAll(setAA); - assert updated.isEmpty(); - return updated; - } - - - @Benchmark - public VectorSet mRetainAllFromDifferentTypeAllRetained() { - VectorSet set = setA; - VectorSet updated = set.retainAll(data.setA); - assert updated == setA; - return updated; - } - - @Benchmark - public VectorSet mRetainAllFromDifferentTypeNoneRetained() { - VectorSet set = setA; - VectorSet updated = set.retainAll(data.setB); - assert updated.isEmpty(); - return updated; - } - - @Benchmark - public VectorSet mRetainAllFromSameTypeAllRetained() { - VectorSet set = setA; - VectorSet updated = set.retainAll(setAA); - assert updated == setA; - return updated; - } - - - @Benchmark - public VectorSet mRetainAllFromSameTypeNoneRetained() { - VectorSet set = setA; - VectorSet updated = set.retainAll(setB); - assert updated.isEmpty(); - return updated; - } -/* - @Benchmark - public int mIterate() { - int sum = 0; - for (Key k : setA) { - sum += k.value; - } - return sum; - } - - @Benchmark - public VectorSet mRemoveThenAdd() { - Key key = data.nextKeyInA(); - return setA.remove(key).add(key); - } - - @Benchmark - public Key mHead() { - return setA.iterator().next(); - } - - @Benchmark - public VectorSet mTail() { - return setA.remove(setA.iterator().next()); - } - - @Benchmark - public boolean mContainsFound() { - Key key = data.nextKeyInA(); - return setA.contains(key); - } - - @Benchmark - public boolean mContainsNotFound() { - Key key = data.nextKeyInB(); - return setA.contains(key); - } -*/ -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jol/ChampMapJol.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jol/ChampMapJol.java deleted file mode 100644 index f7d5a2aed..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jol/ChampMapJol.java +++ /dev/null @@ -1,94 +0,0 @@ -package org.jhotdraw8.collection.jol; - -import org.jhotdraw8.collection.ChampMap; -import org.jhotdraw8.collection.jmh.Key; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.Collections; - -/** - *
- * class org.jhotdraw8.collection.champ.ChampMap with 1000000 elements.
- * total size              : 94362736
- * element size            : 48
- * data size               : 48000000 50%
- * data structure size     : 46362736 49%
- * ----footprint---
- * org.jhotdraw8.collection.champ.ChampMap@723e88f9d footprint:
- *      COUNT       AVG       SUM   DESCRIPTION
- *     344064        32  11353488   [Ljava.lang.Object;
- *    1000000        24  24000000   java.util.AbstractMap$SimpleImmutableEntry
- *          1        16        16   org.jhotdraw8.collection.IdentityObject
- *          1        32        32   org.jhotdraw8.collection.champ.ChampMap
- *     343961        32  11006752   org.jhotdraw8.collection.champ.MutableBitmapIndexedNode
- *        102        24      2448   org.jhotdraw8.collection.champ.MutableHashCollisionNode
- *    2000000        24  48000000   org.jhotdraw8.collection.jmh.Key
- *    3688129            94362736   (total)
- * 
- */ -public class ChampMapJol extends AbstractJol { - - /** - *
-     * class org.jhotdraw8.collection.champ.ChampMap with 1000 elements.
-     * total size              : 94744
-     * element size            : 48
-     * data size               : 48000 50%
-     * data structure size     : 46744 49%
-     * ----footprint---
-     * org.jhotdraw8.collection.champ.ChampMap@7a3793c7d footprint:
-     *      COUNT       AVG       SUM   DESCRIPTION
-     *        350        32     11528   [Ljava.lang.Object;
-     *       1000        24     24000   java.util.AbstractMap$SimpleImmutableEntry
-     *          1        16        16   org.jhotdraw8.collection.IdentityObject
-     *          1        32        32   org.jhotdraw8.collection.champ.ChampMap
-     *        349        32     11168   org.jhotdraw8.collection.champ.MutableBitmapIndexedNode
-     *       2000        24     48000   org.jhotdraw8.collection.jmh.Key
-     *       3701               94744   (total)
-     * 
- */ - @Test - @Disabled - public void estimateMemoryUsage() { - int size = 1_000; - final int mask = ~64; - var data = generateMap(size, mask); - ChampMap mapA = ChampMap.copyOf(data); - estimateMemoryUsage(mapA, mapA.iterator().next(), mapA.size()); - } - - /** - *
-     * class org.jhotdraw8.collection.champ.ChampMap with 250 elements.
-     * total size              : 23224
-     * element size            : 48
-     * data size               : 12000 51%
-     * data structure size     : 11224 48%
-     * ----footprint---
-     * org.jhotdraw8.collection.champ.ChampMap@651aed93d footprint:
-     * COUNT       AVG       SUM   DESCRIPTION
-     *  79        33      2664   [Ljava.lang.Object;
-     * 250        24      6000   java.util.AbstractMap$SimpleImmutableEntry
-     *   2        16        32   org.jhotdraw8.collection.IdentityObject
-     *   1        32        32   org.jhotdraw8.collection.champ.ChampMap
-     *  78        32      2496   org.jhotdraw8.collection.champ.MutableBitmapIndexedNode
-     * 500        24     12000   org.jhotdraw8.collection.jmh.Key
-     * 910               23224   (total)
-     * 
- */ - @Test - public void estimateMemoryUsageAfter75PercentRandomRemoves() { - int size = 1_000; - final int mask = ~64; - var data = generateMap(size, mask); - ChampMap mapA = ChampMap.copyOf(data); - - ArrayList keys = new ArrayList<>(data.keySet()); - Collections.shuffle(keys); - mapA = mapA.removeAll(keys.subList(0, (int) (keys.size() * 0.75))); - - estimateMemoryUsage(mapA, mapA.iterator().next(), mapA.size()); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jol/ChampSetJol.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jol/ChampSetJol.java deleted file mode 100644 index 0ef7c9899..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jol/ChampSetJol.java +++ /dev/null @@ -1,107 +0,0 @@ -package org.jhotdraw8.collection.jol; - -import org.jhotdraw8.collection.ChampSet; -import org.jhotdraw8.collection.jmh.Key; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.Collections; - -/** - *
- * copyOf
- *
- * class org.jhotdraw8.collection.champ.ChampSet with 1000000 elements.
- *
- * total size              : 46371840
- * element size            : 24
- * data size               : 24000000 51%
- * data structure size     : 22371840 48%
- * 
- *
- * oneByOne
- *
- * class org.jhotdraw8.collection.champ.ChampSet with 1000000 elements.
- *
- * total size              : 43618704
- * element size            : 24
- * data size               : 24000000 55%
- * data structure size     : 19618704 44%
- *
- * ----footprint---
- * org.jhotdraw8.collection.champ.ChampSet@1130520dd footprint:
- *      COUNT       AVG       SUM   DESCRIPTION
- *     344264        32  11356360   [Ljava.lang.Object;
- *     344140        24   8259360   org.jhotdraw8.collection.champ.BitmapIndexedNode
- *          1        32        32   org.jhotdraw8.collection.champ.ChampSet
- *        123        24      2952   org.jhotdraw8.collection.champ.HashCollisionNode
- *    1000000        24  24000000   org.jhotdraw8.collection.jmh.Key
- *    1688528            43618704   (total)
- *
- * Addresses are stable after 1 tries.
- * 
- */ -public class ChampSetJol extends AbstractJol { - - /** - *
-     * class org.jhotdraw8.collection.champ.ChampSet with 1000 elements.
-     * total size              : 47168
-     * element size            : 24
-     * data size               : 24000 50%
-     * data structure size     : 23168 49%
-     * ----footprint---
-     * org.jhotdraw8.collection.champ.ChampSet@895e367d footprint:
-     *      COUNT       AVG       SUM   DESCRIPTION
-     *        359        32     11664   [Ljava.lang.Object;
-     *          1        16        16   org.jhotdraw8.collection.IdentityObject
-     *          1        32        32   org.jhotdraw8.collection.champ.ChampSet
-     *        358        32     11456   org.jhotdraw8.collection.champ.MutableBitmapIndexedNode
-     *       1000        24     24000   org.jhotdraw8.collection.jmh.Key
-     *       1719               47168   (total)
-     * 
- */ - @Test - public void estimateMemoryUsage() { - int size = 1_000; - final int mask = ~64; - var data = generateSet(size, mask); - ChampSet setA = ChampSet.copyOf(data); - estimateMemoryUsage(setA, setA.iterator().next(), setA.size()); - } - - /** - *
-     * class org.jhotdraw8.collection.champ.ChampSet with 250 elements.
-     * total size              : 11760
-     * element size            : 24
-     * data size               : 6000 51%
-     * data structure size     : 5760 48%
-     * ----footprint---
-     * org.jhotdraw8.collection.champ.ChampSet@1b266842d footprint:
-     *      COUNT       AVG       SUM   DESCRIPTION
-     *         89        32      2880   [Ljava.lang.Object;
-     *          2        16        32   org.jhotdraw8.collection.IdentityObject
-     *          1        32        32   org.jhotdraw8.collection.champ.ChampSet
-     *         88        32      2816   org.jhotdraw8.collection.champ.MutableBitmapIndexedNode
-     *        250        24      6000   org.jhotdraw8.collection.jmh.Key
-     *        430               11760   (total)
-     * 
- */ - @Test - public void estimateMemoryUsageAfter75PercentRandomRemoves() { - int size = 1_000; - final int mask = ~64; - var data = generateSet(size, mask); - ChampSet setA = ChampSet.copyOf(data); - - ArrayList keys = new ArrayList<>(data); - Collections.shuffle(keys); - setA = setA.removeAll(keys.subList(0, (int) (keys.size() * 0.75))); - - - estimateMemoryUsage(setA, setA.iterator().next(), setA.size()); - } - - -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jol/VectorMapJol.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jol/VectorMapJol.java deleted file mode 100644 index bb533c357..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/jol/VectorMapJol.java +++ /dev/null @@ -1,105 +0,0 @@ -package org.jhotdraw8.collection.jol; - -import org.jhotdraw8.collection.VectorMap; -import org.jhotdraw8.collection.jmh.Key; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.Collections; - -/** - * VectorMapJol. - *
- * class org.jhotdraw8.collection.VectorMap with 1000000 elements.
- * total size              : 99007984
- * element size            : 48
- * data size               : 48000000 48%
- * data structure size     : 51007984 51%
- * ----footprint---
- * org.jhotdraw8.collection.VectorMap@37911f88d footprint:
- *      COUNT       AVG       SUM   DESCRIPTION
- *     376323        42  15998672   [Ljava.lang.Object;
- *          1        16        16   org.jhotdraw8.collection.IdentityObject
- *          1        40        40   org.jhotdraw8.collection.VectorList
- *          1        40        40   org.jhotdraw8.collection.VectorMap
- *     343961        32  11006752   org.jhotdraw8.collection.impl.champ.MutableBitmapIndexedNode
- *        102        24      2448   org.jhotdraw8.collection.impl.champ.MutableHashCollisionNode
- *    1000000        24  24000000   org.jhotdraw8.collection.impl.champ.SequencedEntry
- *          1        16        16   org.jhotdraw8.collection.impl.vector.ArrayType$ObjectArrayType
- *    2000000        24  48000000   org.jhotdraw8.collection.jmh.Key
- *    3720390            99007984   (total)
- * 
- */ -public class VectorMapJol extends AbstractJol { - - /** - *
-     * class org.jhotdraw8.collection.VectorMap with 1000 elements.
-     * total size              : 99464
-     * element size            : 48
-     * data size               : 48000 48%
-     * data structure size     : 51464 51%
-     * ----footprint---
-     * org.jhotdraw8.collection.VectorMap@5669c5fbd footprint:
-     *      COUNT       AVG       SUM   DESCRIPTION
-     *        383        42     16184   [Ljava.lang.Object;
-     *          1        16        16   org.jhotdraw8.collection.IdentityObject
-     *          1        40        40   org.jhotdraw8.collection.VectorList
-     *          1        40        40   org.jhotdraw8.collection.VectorMap
-     *        349        32     11168   org.jhotdraw8.collection.impl.champ.MutableBitmapIndexedNode
-     *       1000        24     24000   org.jhotdraw8.collection.impl.champ.SequencedEntry
-     *          1        16        16   org.jhotdraw8.collection.impl.vector.ArrayType$ObjectArrayType
-     *       2000        24     48000   org.jhotdraw8.collection.jmh.Key
-     *       3736               99464   (total)
-     * 
- */ - @Test - @Disabled - - public void estimateMemoryUsage() { - int size = 1_000; - final int mask = ~64; - var data = generateMap(size, mask); - VectorMap mapA = VectorMap.copyOf(data); - estimateMemoryUsage(mapA, mapA.iterator().next(), mapA.size()); - } - - /** - *
-     * class org.jhotdraw8.collection.VectorMap with 250 elements.
-     * total size              : 29528
-     * element size            : 48
-     * data size               : 12000 40%
-     * data structure size     : 17528 59%
-     * ----footprint---
-     * org.jhotdraw8.collection.VectorMap@2d9caaebd footprint:
-     *      COUNT       AVG       SUM   DESCRIPTION
-     *         93        53      4936   [Ljava.lang.Object;
-     *          1        16        16   org.jhotdraw8.collection.IdentityObject
-     *          1        40        40   org.jhotdraw8.collection.VectorList
-     *          1        40        40   org.jhotdraw8.collection.VectorMap
-     *         75        32      2400   org.jhotdraw8.collection.impl.champ.MutableBitmapIndexedNode
-     *        252        24      6048   org.jhotdraw8.collection.impl.champ.SequencedEntry
-     *        164        24      3936   org.jhotdraw8.collection.impl.champ.VectorTombstone
-     *          1        16        16   org.jhotdraw8.collection.impl.vector.ArrayType$ObjectArrayType
-     *        504        24     12096   org.jhotdraw8.collection.jmh.Key
-     *       1092               29528   (total)
-     * 
- */ - @Test - @Disabled - - public void estimateMemoryUsageAfter75PercentRandomRemoves() { - int size = 1_000; - final int mask = ~64; - var data = generateMap(size, mask); - VectorMap mapA = VectorMap.copyOf(data); - - ArrayList keys = new ArrayList<>(data.keySet()); - Collections.shuffle(keys); - mapA = mapA.removeAll(keys.subList(0, (int) (keys.size() * 0.75))); - - estimateMemoryUsage(mapA, mapA.iterator().next(), mapA.size()); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntArrayDequeTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntArrayDequeTest.java deleted file mode 100644 index 044df59ab..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntArrayDequeTest.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * @(#)IntArrayDequeTest.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.primitive; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.AbstractIntSequencedCollectionTest; - -/** - * Tests {@link IntArrayDeque}. - */ -public class IntArrayDequeTest extends AbstractIntSequencedCollectionTest { - @Override - protected @NonNull IntSequencedCollection newInstance() { - return new IntArrayDeque(); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntArrayListTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntArrayListTest.java deleted file mode 100644 index 708719feb..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntArrayListTest.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * @(#)IntArrayListTest.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.primitive; - -import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.AbstractIntSequencedCollectionTest; - -/** - * Tests {@link IntArrayList}. - */ -public class IntArrayListTest extends AbstractIntSequencedCollectionTest { - @Override - protected @NonNull IntSequencedCollection newInstance() { - return new IntArrayList(); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntSetTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntSetTest.java deleted file mode 100644 index 00a5698d8..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/IntSetTest.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * @(#)IntSetTest.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.primitive; - -import org.junit.jupiter.api.Test; - -import java.util.BitSet; -import java.util.Random; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class IntSetTest { - private DenseIntSet8Bit newInstance(int size) { - return new DenseIntSet8Bit(size); - } - - @Test - public void clearAndSetUntilMarkerOverflows() { - DenseIntSet8Bit actual = newInstance(8); - DenseIntSet8Bit actual2 = newInstance(8); - BitSet expected = new BitSet(8); - - // we intentionally clear actual2 two times here - actual2.clear(); - actual2.clear(); - - Random rng = new Random(0); - - for (int i = 0; i < 300; i++) { - expected.clear(); - actual.clear(); - actual2.clear(); - - for (int j = 0; j < 16; j++) { - int index = rng.nextInt(8); - boolean remove = rng.nextBoolean(); - - - boolean expectedChanged; - boolean actualChanged; - boolean actual2Changed; - if (remove) { - expectedChanged = expected.get(index); - expected.clear(index); - actualChanged = actual.removeAsInt(index); - actual2Changed = actual2.removeAsInt(index); - } else { - expectedChanged = !expected.get(index); - expected.set(index); - actualChanged = actual.addAsInt(index); - actual2Changed = actual2.addAsInt(index); - } - - assertEquals(expectedChanged, actualChanged, "index=" + index + " must have changed"); - assertEquals(actualChanged, actual2Changed, "index=" + index + " must have changed"); - - } - assertEquals(expected.toString(), actual.toString()); - assertEquals(expected.toString(), actual2.toString()); - assertArrayEquals(expected.toLongArray(), actual.toLongArray()); - assertArrayEquals(expected.toLongArray(), actual2.toLongArray()); - assertEquals(expected.hashCode(), actual.hashCode()); - assertEquals(expected.hashCode(), actual2.hashCode()); - assertEquals(actual, actual2); - } - } - - @Test - public void resizeSet() { - int size = 8; - - DenseIntSet8Bit actual = newInstance(size); - BitSet expected = new BitSet(size); - - Random rng = new Random(0); - - for (int i = 0; i < 300; i++) { - - boolean resize = rng.nextBoolean(); - if (resize) { - size = 1 + rng.nextInt(128); - BitSet temp = new BitSet(size); - for (int j = 0; j < size; j++) { - temp.set(j, expected.get(j)); - } - expected = temp; - actual.setCapacity(size); - - assertEquals(expected.toString(), actual.toString()); - assertArrayEquals(expected.toLongArray(), actual.toLongArray()); - assertEquals(expected.hashCode(), actual.hashCode()); - } - - for (int j = 0; j < size * 2; j++) { - int index = rng.nextInt(size); - boolean remove = rng.nextBoolean(); - - - boolean expectedChanged; - boolean actualChanged; - if (remove) { - expectedChanged = expected.get(index); - expected.clear(index); - actualChanged = actual.removeAsInt(index); - } else { - expectedChanged = !expected.get(index); - expected.set(index); - actualChanged = actual.addAsInt(index); - } - assertEquals(expectedChanged, actualChanged, "index=" + index + " must have changed"); - } - - assertEquals(expected.toString(), actual.toString()); - assertArrayEquals(expected.toLongArray(), actual.toLongArray()); - assertEquals(expected.hashCode(), actual.hashCode()); - } - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/LongArrayDequeTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/LongArrayDequeTest.java deleted file mode 100755 index f81e35935..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/LongArrayDequeTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * @(#)LongArrayDequeTest.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.collection.primitive; - - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; - -/** - * @author werni - */ -public class LongArrayDequeTest { - - public LongArrayDequeTest() { - } - - /** - * Test of addFirst method, of class LongArrayDeque. - */ - @Test - public void testAddFirst() { - int e = 1; - LongArrayDeque instance = new LongArrayDeque(); - instance.addFirstAsLong(e); - assertFalse(instance.isEmpty()); - - assertEquals(1, instance.getFirstAsLong()); - - instance.addFirstAsLong(2); - assertEquals(2, instance.getFirstAsLong()); - assertEquals(2, instance.size()); - } - - /** - * Test of addLast method, of class LongArrayDeque. - */ - @Test - public void testAddLast() { - int e = 1; - LongArrayDeque instance = new LongArrayDeque(); - instance.addLastAsLong(e); - assertFalse(instance.isEmpty()); - - assertEquals(1, instance.getLastAsLong()); - - instance.addLastAsLong(2); - assertEquals(2, instance.getLastAsLong()); - assertEquals(2, instance.size()); - } - - @Test - public void testAddAll() { - LongArrayDeque instance = new LongArrayDeque(4); - instance.addLastAllAsLong(new long[]{1, 2, 3}); - instance.addLastAllAsLong(new long[]{4, 5}); - instance.addLastAllAsLong(new long[]{0, 6, 7}, 1, 2); - assertEquals(1, instance.removeFirstAsLong()); - assertEquals(2, instance.removeFirstAsLong()); - instance.addLastAllAsLong(new long[]{0, 8, 9, 0}, 1, 2); - instance.addLastAllAsLong(new long[]{0, 10, 11, 0}, 1, 2); - - LongArrayDeque expected = new LongArrayDeque(0); - expected.addLastAllAsLong(new long[]{3, 4, 5, 6, 7, 8, 9, 10, 11}); - assertEquals(expected, instance); - assertEquals(expected.hashCode(), instance.hashCode()); - - assertEquals(3, instance.removeFirstAsLong()); - assertEquals(4, instance.removeFirstAsLong()); - assertEquals(5, instance.removeFirstAsLong()); - assertEquals(11, instance.removeLastAsLong()); - assertEquals(10, instance.removeLastAsLong()); - instance.addLastAllAsLong(new long[]{10, 11, 12, 13, 14, 15, 16, 17, 18, 19}); - - expected.clear(); - expected.addLastAllAsLong(new long[]{6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}); - assertEquals(expected, instance); - assertEquals(expected.hashCode(), instance.hashCode()); - } -} diff --git a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/LongArrayHeapTest.java b/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/LongArrayHeapTest.java deleted file mode 100644 index 34d27aa1a..000000000 --- a/org.jhotdraw8.collection/src/test/java/org.jhotdraw8.collection/org/jhotdraw8/collection/primitive/LongArrayHeapTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * @(#)LongArrayHeapTest.java - * Copyright © 2022 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.collection.primitive; - - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class LongArrayHeapTest { - - @Test - public void test() { - - // Creating object opf class in main() method - final LongArrayHeap minHeap = new LongArrayHeap(15); - - // Inserting element to minHeap - // using insert() method - - // Custom input entries - minHeap.addAsLong(5); - minHeap.addAsLong(3); - minHeap.addAsLong(17); - minHeap.addAsLong(10); - minHeap.addAsLong(84); - minHeap.addAsLong(19); - minHeap.addAsLong(6); - minHeap.addAsLong(22); - minHeap.addAsLong(9); - - // Print all elements of the heap - // minHeap.print(); - - // Removing minimum value from above heap - long removed = minHeap.removeAsLong(); - assertEquals(3, removed); - } -} \ No newline at end of file diff --git a/org.jhotdraw8.css/pom.xml b/org.jhotdraw8.css/pom.xml index d85433e13..edbba930a 100644 --- a/org.jhotdraw8.css/pom.xml +++ b/org.jhotdraw8.css/pom.xml @@ -55,6 +55,10 @@ org.jhotdraw8.collection + ch.randelshofer + org.jhotdraw8.icollection + + org.junit.jupiter junit-jupiter test @@ -68,5 +72,9 @@ org.openjfx javafx-graphics + + ch.randelshofer + org.jhotdraw8.icollection + diff --git a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/module-info.java b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/module-info.java index f5920a5df..4f4336810 100755 --- a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/module-info.java +++ b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/module-info.java @@ -14,6 +14,7 @@ requires static org.jhotdraw8.annotation; requires transitive org.jhotdraw8.base; requires transitive org.jhotdraw8.collection; + requires org.jhotdraw8.icollection; exports org.jhotdraw8.css.ast; exports org.jhotdraw8.css.converter; diff --git a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/ast/AtRule.java b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/ast/AtRule.java index ff31be117..e0915086d 100755 --- a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/ast/AtRule.java +++ b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/ast/AtRule.java @@ -6,10 +6,10 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; -import org.jhotdraw8.collection.readonly.ReadOnlyList; import org.jhotdraw8.css.parser.CssToken; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; +import org.jhotdraw8.icollection.readonly.ReadOnlyList; import java.util.List; diff --git a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/ast/Declaration.java b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/ast/Declaration.java index 7ff1f514e..4d11e5c39 100755 --- a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/ast/Declaration.java +++ b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/ast/Declaration.java @@ -6,9 +6,9 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.parser.CssToken; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.List; diff --git a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/ast/SelectorGroup.java b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/ast/SelectorGroup.java index 0e4909188..ca8f4d7e0 100755 --- a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/ast/SelectorGroup.java +++ b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/ast/SelectorGroup.java @@ -6,11 +6,11 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.readonly.ReadOnlyList; import org.jhotdraw8.css.model.SelectorModel; import org.jhotdraw8.css.parser.CssToken; import org.jhotdraw8.css.parser.CssTokenType; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.readonly.ReadOnlyList; import java.util.List; import java.util.Objects; diff --git a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/ast/StyleRule.java b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/ast/StyleRule.java index 8d4476194..1f9ba848c 100755 --- a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/ast/StyleRule.java +++ b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/ast/StyleRule.java @@ -6,8 +6,8 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.List; diff --git a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/ast/Stylesheet.java b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/ast/Stylesheet.java index 62a41e95b..47b4f3fa0 100755 --- a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/ast/Stylesheet.java +++ b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/ast/Stylesheet.java @@ -6,9 +6,9 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; -import org.jhotdraw8.collection.readonly.ReadOnlyList; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; +import org.jhotdraw8.icollection.readonly.ReadOnlyList; import java.net.URI; import java.util.List; diff --git a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/converter/CssConverter.java b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/converter/CssConverter.java index 65bb1e653..9a9a0303f 100755 --- a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/converter/CssConverter.java +++ b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/converter/CssConverter.java @@ -10,11 +10,11 @@ import org.jhotdraw8.base.converter.IdFactory; import org.jhotdraw8.base.converter.IdResolver; import org.jhotdraw8.base.converter.IdSupplier; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.parser.CssToken; import org.jhotdraw8.css.parser.CssTokenizer; import org.jhotdraw8.css.parser.StreamCssTokenizer; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.io.IOException; import java.io.UncheckedIOException; diff --git a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/converter/CssListConverter.java b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/converter/CssListConverter.java index 1d3c66d86..635ed4f10 100755 --- a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/converter/CssListConverter.java +++ b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/converter/CssListConverter.java @@ -8,12 +8,12 @@ import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.IdResolver; import org.jhotdraw8.base.converter.IdSupplier; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.parser.CssToken; import org.jhotdraw8.css.parser.CssTokenType; import org.jhotdraw8.css.parser.CssTokenizer; import org.jhotdraw8.css.parser.StreamCssTokenizer; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.io.IOException; import java.text.ParseException; diff --git a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/converter/CssMappedConverter.java b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/converter/CssMappedConverter.java index a143af5df..917ef3e1f 100755 --- a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/converter/CssMappedConverter.java +++ b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/converter/CssMappedConverter.java @@ -8,10 +8,10 @@ import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.IdResolver; import org.jhotdraw8.base.converter.IdSupplier; -import org.jhotdraw8.collection.readonly.ReadOnlyMap; import org.jhotdraw8.css.parser.CssToken; import org.jhotdraw8.css.parser.CssTokenType; import org.jhotdraw8.css.parser.CssTokenizer; +import org.jhotdraw8.icollection.readonly.ReadOnlyMap; import java.io.IOException; import java.text.ParseException; diff --git a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/converter/CssSetConverter.java b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/converter/CssSetConverter.java index 6d6c97fc4..d4e3b2a8c 100755 --- a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/converter/CssSetConverter.java +++ b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/converter/CssSetConverter.java @@ -8,14 +8,14 @@ import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.IdResolver; import org.jhotdraw8.base.converter.IdSupplier; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.VectorSet; -import org.jhotdraw8.collection.immutable.ImmutableList; -import org.jhotdraw8.collection.immutable.ImmutableSequencedSet; import org.jhotdraw8.css.parser.CssToken; import org.jhotdraw8.css.parser.CssTokenType; import org.jhotdraw8.css.parser.CssTokenizer; import org.jhotdraw8.css.parser.StreamCssTokenizer; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.VectorSet; +import org.jhotdraw8.icollection.immutable.ImmutableList; +import org.jhotdraw8.icollection.immutable.ImmutableSequencedSet; import java.io.IOException; import java.text.ParseException; diff --git a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/function/VarCssFunction.java b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/function/VarCssFunction.java index 22281f4bb..0feff6adf 100755 --- a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/function/VarCssFunction.java +++ b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/function/VarCssFunction.java @@ -5,13 +5,13 @@ package org.jhotdraw8.css.function; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.readonly.ReadOnlyList; import org.jhotdraw8.css.manager.CssFunctionProcessor; import org.jhotdraw8.css.model.SelectorModel; import org.jhotdraw8.css.parser.CssToken; import org.jhotdraw8.css.parser.CssTokenType; import org.jhotdraw8.css.parser.CssTokenizer; import org.jhotdraw8.css.parser.ListCssTokenizer; +import org.jhotdraw8.icollection.readonly.ReadOnlyList; import java.io.IOException; import java.text.ParseException; diff --git a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/manager/CssFunctionProcessor.java b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/manager/CssFunctionProcessor.java index e7727a4f1..2ff98acd1 100755 --- a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/manager/CssFunctionProcessor.java +++ b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/manager/CssFunctionProcessor.java @@ -5,14 +5,14 @@ package org.jhotdraw8.css.manager; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; -import org.jhotdraw8.collection.readonly.ReadOnlyList; import org.jhotdraw8.css.function.CssFunction; import org.jhotdraw8.css.model.SelectorModel; import org.jhotdraw8.css.parser.CssToken; import org.jhotdraw8.css.parser.CssTokenizer; import org.jhotdraw8.css.parser.ListCssTokenizer; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; +import org.jhotdraw8.icollection.readonly.ReadOnlyList; import java.io.IOException; import java.text.ParseException; diff --git a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/manager/SimpleCssFunctionProcessor.java b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/manager/SimpleCssFunctionProcessor.java index 273263e0b..734ad4ae5 100755 --- a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/manager/SimpleCssFunctionProcessor.java +++ b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/manager/SimpleCssFunctionProcessor.java @@ -5,15 +5,15 @@ package org.jhotdraw8.css.manager; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; -import org.jhotdraw8.collection.readonly.ReadOnlyList; import org.jhotdraw8.css.function.CssFunction; import org.jhotdraw8.css.model.SelectorModel; import org.jhotdraw8.css.parser.CssToken; import org.jhotdraw8.css.parser.CssTokenType; import org.jhotdraw8.css.parser.CssTokenizer; import org.jhotdraw8.css.parser.ListCssTokenizer; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; +import org.jhotdraw8.icollection.readonly.ReadOnlyList; import java.io.IOException; import java.text.ParseException; diff --git a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/manager/SimpleStylesheetsManager.java b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/manager/SimpleStylesheetsManager.java index 7c1ce5966..2be61f275 100755 --- a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/manager/SimpleStylesheetsManager.java +++ b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/manager/SimpleStylesheetsManager.java @@ -10,23 +10,39 @@ import org.jhotdraw8.base.converter.SimpleUriResolver; import org.jhotdraw8.base.converter.UriResolver; import org.jhotdraw8.base.function.TriConsumer; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.OrderedPair; import org.jhotdraw8.collection.pair.SimpleOrderedPair; -import org.jhotdraw8.collection.readonly.ReadOnlyList; -import org.jhotdraw8.css.ast.*; +import org.jhotdraw8.css.ast.Declaration; +import org.jhotdraw8.css.ast.Selector; +import org.jhotdraw8.css.ast.StyleRule; +import org.jhotdraw8.css.ast.Stylesheet; +import org.jhotdraw8.css.ast.TypeSelector; import org.jhotdraw8.css.function.CssFunction; import org.jhotdraw8.css.model.SelectorModel; import org.jhotdraw8.css.parser.CssParser; import org.jhotdraw8.css.parser.CssToken; import org.jhotdraw8.css.parser.CssTokenType; import org.jhotdraw8.css.value.QualifiedName; +import org.jhotdraw8.icollection.immutable.ImmutableList; +import org.jhotdraw8.icollection.readonly.ReadOnlyList; import java.io.IOException; import java.net.URI; import java.text.ParseException; -import java.util.*; -import java.util.concurrent.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executor; +import java.util.concurrent.ForkJoinPool; +import java.util.concurrent.FutureTask; import java.util.function.Supplier; import java.util.logging.Level; import java.util.stream.Collectors; diff --git a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/model/DocumentSelectorModel.java b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/model/DocumentSelectorModel.java index fca99fde2..0a44e4b75 100755 --- a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/model/DocumentSelectorModel.java +++ b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/model/DocumentSelectorModel.java @@ -7,13 +7,13 @@ import javafx.css.StyleOrigin; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.ChampSet; -import org.jhotdraw8.collection.readonly.ReadOnlyList; -import org.jhotdraw8.collection.readonly.ReadOnlySet; import org.jhotdraw8.css.ast.TypeSelector; import org.jhotdraw8.css.parser.CssToken; import org.jhotdraw8.css.parser.StreamCssTokenizer; import org.jhotdraw8.css.value.QualifiedName; +import org.jhotdraw8.icollection.ChampSet; +import org.jhotdraw8.icollection.readonly.ReadOnlyList; +import org.jhotdraw8.icollection.readonly.ReadOnlySet; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; diff --git a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/model/SelectorModel.java b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/model/SelectorModel.java index 9f43a9905..9907f1f37 100755 --- a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/model/SelectorModel.java +++ b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/model/SelectorModel.java @@ -8,10 +8,10 @@ import javafx.css.StyleOrigin; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.readonly.ReadOnlyList; -import org.jhotdraw8.collection.readonly.ReadOnlySet; import org.jhotdraw8.css.parser.CssToken; import org.jhotdraw8.css.value.QualifiedName; +import org.jhotdraw8.icollection.readonly.ReadOnlyList; +import org.jhotdraw8.icollection.readonly.ReadOnlySet; import java.text.ParseException; import java.util.List; diff --git a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/model/StyleableSelectorModel.java b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/model/StyleableSelectorModel.java index ba27ea6bb..cdc3fff0f 100755 --- a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/model/StyleableSelectorModel.java +++ b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/model/StyleableSelectorModel.java @@ -13,12 +13,12 @@ import javafx.css.StyleableProperty; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.ChampSet; -import org.jhotdraw8.collection.readonly.ReadOnlyList; -import org.jhotdraw8.collection.readonly.ReadOnlySet; import org.jhotdraw8.css.parser.CssToken; import org.jhotdraw8.css.parser.StreamCssTokenizer; import org.jhotdraw8.css.value.QualifiedName; +import org.jhotdraw8.icollection.ChampSet; +import org.jhotdraw8.icollection.readonly.ReadOnlyList; +import org.jhotdraw8.icollection.readonly.ReadOnlySet; import java.io.IOException; import java.util.Collection; diff --git a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/parser/ListCssTokenizer.java b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/parser/ListCssTokenizer.java index 5771fb2e5..0e1e5ae46 100755 --- a/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/parser/ListCssTokenizer.java +++ b/org.jhotdraw8.css/src/main/java/org.jhotdraw8.css/org/jhotdraw8/css/parser/ListCssTokenizer.java @@ -6,10 +6,10 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; -import org.jhotdraw8.collection.readonly.ReadOnlyList; import org.jhotdraw8.css.ast.SourceLocator; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; +import org.jhotdraw8.icollection.readonly.ReadOnlyList; import java.util.List; diff --git a/org.jhotdraw8.css/src/test/java/org.jhotdraw8.css/org/jhotdraw8/css/AbstractCssFunctionProcessorTest.java b/org.jhotdraw8.css/src/test/java/org.jhotdraw8.css/org/jhotdraw8/css/AbstractCssFunctionProcessorTest.java index 79e0c986f..be093409d 100755 --- a/org.jhotdraw8.css/src/test/java/org.jhotdraw8.css/org/jhotdraw8/css/AbstractCssFunctionProcessorTest.java +++ b/org.jhotdraw8.css/src/test/java/org.jhotdraw8.css/org/jhotdraw8/css/AbstractCssFunctionProcessorTest.java @@ -6,13 +6,13 @@ package org.jhotdraw8.css; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.manager.CssFunctionProcessor; import org.jhotdraw8.css.model.DocumentSelectorModel; import org.jhotdraw8.css.parser.CssToken; import org.jhotdraw8.css.parser.CssTokenType; import org.jhotdraw8.css.parser.StreamCssTokenizer; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.InputSource; diff --git a/org.jhotdraw8.css/src/test/java/org.jhotdraw8.css/org/jhotdraw8/css/CssParserTest.java b/org.jhotdraw8.css/src/test/java/org.jhotdraw8.css/org/jhotdraw8/css/CssParserTest.java index 664f8dc87..3d7693670 100755 --- a/org.jhotdraw8.css/src/test/java/org.jhotdraw8.css/org/jhotdraw8/css/CssParserTest.java +++ b/org.jhotdraw8.css/src/test/java/org.jhotdraw8.css/org/jhotdraw8/css/CssParserTest.java @@ -5,7 +5,6 @@ package org.jhotdraw8.css; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.readonly.ReadOnlyList; import org.jhotdraw8.css.ast.Declaration; import org.jhotdraw8.css.ast.Rule; import org.jhotdraw8.css.ast.SelectorGroup; @@ -13,6 +12,7 @@ import org.jhotdraw8.css.ast.Stylesheet; import org.jhotdraw8.css.model.DocumentSelectorModel; import org.jhotdraw8.css.parser.CssParser; +import org.jhotdraw8.icollection.readonly.ReadOnlyList; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.TestFactory; import org.w3c.dom.Document; diff --git a/org.jhotdraw8.css/src/test/java/org.jhotdraw8.css/org/jhotdraw8/css/ExtendedCssFunctionProcessorTest.java b/org.jhotdraw8.css/src/test/java/org.jhotdraw8.css/org/jhotdraw8/css/ExtendedCssFunctionProcessorTest.java index e6ec5461f..3bd3c78c3 100755 --- a/org.jhotdraw8.css/src/test/java/org.jhotdraw8.css/org/jhotdraw8/css/ExtendedCssFunctionProcessorTest.java +++ b/org.jhotdraw8.css/src/test/java/org.jhotdraw8.css/org/jhotdraw8/css/ExtendedCssFunctionProcessorTest.java @@ -6,7 +6,6 @@ package org.jhotdraw8.css; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.function.AttrCssFunction; import org.jhotdraw8.css.function.CalcCssFunction; import org.jhotdraw8.css.function.ConcatCssFunction; @@ -18,6 +17,7 @@ import org.jhotdraw8.css.manager.SimpleCssFunctionProcessor; import org.jhotdraw8.css.model.DocumentSelectorModel; import org.jhotdraw8.css.parser.CssToken; +import org.jhotdraw8.icollection.immutable.ImmutableList; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.TestFactory; import org.w3c.dom.Element; diff --git a/org.jhotdraw8.css/src/test/java/org.jhotdraw8.css/org/jhotdraw8/css/SimpleCssFunctionProcessorTest.java b/org.jhotdraw8.css/src/test/java/org.jhotdraw8.css/org/jhotdraw8/css/SimpleCssFunctionProcessorTest.java index 52af43832..8ef64e0cc 100755 --- a/org.jhotdraw8.css/src/test/java/org.jhotdraw8.css/org/jhotdraw8/css/SimpleCssFunctionProcessorTest.java +++ b/org.jhotdraw8.css/src/test/java/org.jhotdraw8.css/org/jhotdraw8/css/SimpleCssFunctionProcessorTest.java @@ -6,7 +6,6 @@ package org.jhotdraw8.css; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.function.AttrCssFunction; import org.jhotdraw8.css.function.CalcCssFunction; import org.jhotdraw8.css.function.CssFunction; @@ -15,6 +14,7 @@ import org.jhotdraw8.css.manager.SimpleCssFunctionProcessor; import org.jhotdraw8.css.model.DocumentSelectorModel; import org.jhotdraw8.css.parser.CssToken; +import org.jhotdraw8.icollection.immutable.ImmutableList; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.TestFactory; import org.w3c.dom.Element; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/module-info.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/module-info.java index 3ca3dbec2..d11ce6b7e 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/module-info.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/module-info.java @@ -27,6 +27,7 @@ requires transitive org.jhotdraw8.geom; requires transitive org.jhotdraw8.graph; requires transitive org.jhotdraw8.xml; + requires org.jhotdraw8.icollection; opens org.jhotdraw8.draw.action.images; opens org.jhotdraw8.draw.gui to javafx.fxml; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/action/SelectSameAction.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/action/SelectSameAction.java index cd51eda4b..c803320fb 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/action/SelectSameAction.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/action/SelectSameAction.java @@ -10,11 +10,11 @@ import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.application.action.Action; import org.jhotdraw8.application.resources.Resources; -import org.jhotdraw8.collection.readonly.ReadOnlySet; import org.jhotdraw8.draw.DrawLabels; import org.jhotdraw8.draw.DrawingEditor; import org.jhotdraw8.draw.DrawingView; import org.jhotdraw8.draw.figure.Figure; +import org.jhotdraw8.icollection.readonly.ReadOnlySet; import java.util.ArrayList; import java.util.List; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssBezierNodeListConverter.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssBezierNodeListConverter.java index 278fa207b..156caffcd 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssBezierNodeListConverter.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssBezierNodeListConverter.java @@ -8,7 +8,6 @@ import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.IdResolver; import org.jhotdraw8.base.converter.IdSupplier; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.converter.AbstractCssConverter; import org.jhotdraw8.css.parser.CssToken; import org.jhotdraw8.css.parser.CssTokenType; @@ -17,6 +16,7 @@ import org.jhotdraw8.geom.shape.BezierNode; import org.jhotdraw8.geom.shape.BezierNodePath; import org.jhotdraw8.geom.shape.BezierNodePathBuilder; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.io.IOException; import java.text.ParseException; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssEffectConverter.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssEffectConverter.java index 6f5dd734b..f34f7f640 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssEffectConverter.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssEffectConverter.java @@ -22,14 +22,14 @@ import org.jhotdraw8.base.converter.IdResolver; import org.jhotdraw8.base.converter.IdSupplier; import org.jhotdraw8.base.util.MathUtil; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.converter.CssConverter; import org.jhotdraw8.css.converter.CssKebabCaseEnumConverter; import org.jhotdraw8.css.parser.CssToken; import org.jhotdraw8.css.parser.CssTokenType; import org.jhotdraw8.css.parser.CssTokenizer; import org.jhotdraw8.draw.css.value.CssColor; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.io.IOException; import java.lang.reflect.InvocationTargetException; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssFXPathElementsConverter.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssFXPathElementsConverter.java index 44623af2f..47614b5b1 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssFXPathElementsConverter.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssFXPathElementsConverter.java @@ -12,13 +12,13 @@ import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.IdResolver; import org.jhotdraw8.base.converter.IdSupplier; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.converter.AbstractCssConverter; import org.jhotdraw8.css.parser.CssToken; import org.jhotdraw8.css.parser.CssTokenType; import org.jhotdraw8.css.parser.CssTokenizer; import org.jhotdraw8.geom.FXSvgPaths; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.io.IOException; import java.text.ParseException; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssStrokeStyleConverter.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssStrokeStyleConverter.java index 2d88eea48..21d80046b 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssStrokeStyleConverter.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssStrokeStyleConverter.java @@ -11,8 +11,6 @@ import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.IdResolver; import org.jhotdraw8.base.converter.IdSupplier; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.converter.AbstractCssConverter; import org.jhotdraw8.css.parser.CssToken; import org.jhotdraw8.css.parser.CssTokenType; @@ -20,6 +18,8 @@ import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.css.value.UnitConverter; import org.jhotdraw8.draw.css.value.CssStrokeStyle; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.io.IOException; import java.text.ParseException; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/model/FigureSelectorModel.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/model/FigureSelectorModel.java index 9832bcbe3..55e183a6b 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/model/FigureSelectorModel.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/model/FigureSelectorModel.java @@ -8,8 +8,6 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.readonly.ReadOnlyList; -import org.jhotdraw8.collection.readonly.ReadOnlySet; import org.jhotdraw8.css.ast.TypeSelector; import org.jhotdraw8.css.converter.CssConverter; import org.jhotdraw8.css.converter.CssStringConverter; @@ -25,6 +23,8 @@ import org.jhotdraw8.fxbase.styleable.WritableStyleableMapAccessor; import org.jhotdraw8.fxcollection.typesafekey.CompositeMapAccessor; import org.jhotdraw8.fxcollection.typesafekey.MapAccessor; +import org.jhotdraw8.icollection.readonly.ReadOnlyList; +import org.jhotdraw8.icollection.readonly.ReadOnlySet; import java.io.IOException; import java.text.ParseException; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/CssStrokeStyle.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/CssStrokeStyle.java index acafb7b7a..94e25f199 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/CssStrokeStyle.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/CssStrokeStyle.java @@ -9,9 +9,9 @@ import javafx.scene.shape.StrokeType; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.value.CssSize; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.Objects; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/NamedCssColor.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/NamedCssColor.java index dbda49be4..f9487213b 100644 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/NamedCssColor.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/NamedCssColor.java @@ -8,8 +8,8 @@ import javafx.scene.paint.Color; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.ChampMap; -import org.jhotdraw8.collection.immutable.ImmutableMap; +import org.jhotdraw8.icollection.ChampMap; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.util.LinkedHashMap; import java.util.Map; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/SystemCssColor.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/SystemCssColor.java index 595568d1c..4316499c1 100644 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/SystemCssColor.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/SystemCssColor.java @@ -7,8 +7,8 @@ import javafx.scene.paint.Color; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.ChampMap; -import org.jhotdraw8.collection.immutable.ImmutableMap; +import org.jhotdraw8.icollection.ChampMap; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.util.LinkedHashMap; import java.util.Map; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/AbstractDrawing.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/AbstractDrawing.java index 8dbc876b8..ba1c39edd 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/AbstractDrawing.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/AbstractDrawing.java @@ -20,7 +20,6 @@ import javafx.scene.transform.Transform; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.manager.SimpleStylesheetsManager; import org.jhotdraw8.css.manager.StylesheetsManager; import org.jhotdraw8.css.value.CssSize; @@ -29,6 +28,7 @@ import org.jhotdraw8.draw.css.value.Paintable; import org.jhotdraw8.draw.render.RenderContext; import org.jhotdraw8.fxcollection.typesafekey.Key; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.net.URI; import java.util.ArrayList; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/AbstractFigure.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/AbstractFigure.java index 7a7eb2a60..0ac549d8e 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/AbstractFigure.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/AbstractFigure.java @@ -10,9 +10,6 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.event.Listener; -import org.jhotdraw8.collection.ChampSet; -import org.jhotdraw8.collection.facade.ReadOnlySetFacade; -import org.jhotdraw8.collection.readonly.ReadOnlySet; import org.jhotdraw8.css.manager.StylesheetsManager; import org.jhotdraw8.css.value.CssDefaultableValue; import org.jhotdraw8.css.value.CssDefaulting; @@ -22,6 +19,9 @@ import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.MapAccessor; import org.jhotdraw8.fxcollection.typesafekey.NonNullMapAccessor; +import org.jhotdraw8.icollection.ChampSet; +import org.jhotdraw8.icollection.facade.ReadOnlySetFacade; +import org.jhotdraw8.icollection.readonly.ReadOnlySet; import java.util.Collections; import java.util.IdentityHashMap; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/AbstractLabelConnectionFigure.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/AbstractLabelConnectionFigure.java index d658a78b1..13beb2ca7 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/AbstractLabelConnectionFigure.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/AbstractLabelConnectionFigure.java @@ -12,8 +12,6 @@ import javafx.scene.transform.Transform; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.ChampSet; -import org.jhotdraw8.collection.readonly.ReadOnlySet; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.css.value.UnitConverter; import org.jhotdraw8.draw.connector.Connector; @@ -34,6 +32,8 @@ import org.jhotdraw8.geom.FXGeom; import org.jhotdraw8.geom.FXPreciseRotate; import org.jhotdraw8.geom.PointAndDerivative; +import org.jhotdraw8.icollection.ChampSet; +import org.jhotdraw8.icollection.readonly.ReadOnlySet; import java.util.ArrayList; import java.util.List; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/AbstractLabelFigure.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/AbstractLabelFigure.java index 61a8fdd9a..08cd8a2dd 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/AbstractLabelFigure.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/AbstractLabelFigure.java @@ -19,7 +19,6 @@ import javafx.scene.text.TextBoundsType; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.css.value.UnitConverter; import org.jhotdraw8.draw.connector.Connector; @@ -40,6 +39,7 @@ import org.jhotdraw8.draw.render.RenderContext; import org.jhotdraw8.geom.FXPreciseRotate; import org.jhotdraw8.geom.FXShapes; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.awt.geom.AffineTransform; import java.awt.geom.PathIterator; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/AbstractLineConnectionFigure.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/AbstractLineConnectionFigure.java index d55704de4..aa8a688b4 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/AbstractLineConnectionFigure.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/AbstractLineConnectionFigure.java @@ -9,15 +9,15 @@ import javafx.scene.transform.Transform; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.ChampSet; -import org.jhotdraw8.collection.facade.ReadOnlySetFacade; -import org.jhotdraw8.collection.readonly.ReadOnlySet; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.draw.connector.Connector; import org.jhotdraw8.draw.css.value.CssPoint2D; import org.jhotdraw8.draw.css.value.CssRectangle2D; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.geom.FXTransforms; +import org.jhotdraw8.icollection.ChampSet; +import org.jhotdraw8.icollection.facade.ReadOnlySetFacade; +import org.jhotdraw8.icollection.readonly.ReadOnlySet; import java.util.LinkedHashSet; import java.util.Set; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/BezierFigure.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/BezierFigure.java index 46cdb9b52..8d89176b7 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/BezierFigure.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/BezierFigure.java @@ -14,8 +14,6 @@ import javafx.scene.transform.Transform; import javafx.scene.transform.Translate; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.draw.connector.Connector; import org.jhotdraw8.draw.connector.PathConnector; @@ -36,6 +34,8 @@ import org.jhotdraw8.geom.FXTransforms; import org.jhotdraw8.geom.shape.BezierNode; import org.jhotdraw8.geom.shape.BezierNodePath; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.awt.geom.AffineTransform; import java.awt.geom.PathIterator; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/CombinedPathFigure.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/CombinedPathFigure.java index 6ec4e63dc..5c3026e14 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/CombinedPathFigure.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/CombinedPathFigure.java @@ -11,7 +11,6 @@ import javafx.scene.transform.Transform; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.draw.connector.Connector; import org.jhotdraw8.draw.css.value.CssTransforms; @@ -23,6 +22,7 @@ import org.jhotdraw8.geom.FXShapes; import org.jhotdraw8.geom.FXTransforms; import org.jhotdraw8.geom.SvgPaths; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.awt.*; import java.awt.geom.AffineTransform; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/Drawing.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/Drawing.java index eb935fc5d..c2aacc293 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/Drawing.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/Drawing.java @@ -7,7 +7,6 @@ import javafx.scene.paint.Color; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.SimpleOrderedPair; import org.jhotdraw8.collection.primitive.IntArrayList; import org.jhotdraw8.collection.reflect.TypeToken; @@ -23,6 +22,7 @@ import org.jhotdraw8.fxcollection.typesafekey.SimpleNullableKey; import org.jhotdraw8.graph.SimpleMutableDirectedGraph; import org.jhotdraw8.graph.algo.TopologicalSortAlgo; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.net.URI; import java.nio.file.Paths; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/Figure.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/Figure.java index 3034bfad5..9cfae8fe3 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/Figure.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/Figure.java @@ -15,8 +15,6 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.event.Listener; -import org.jhotdraw8.collection.ChampSet; -import org.jhotdraw8.collection.readonly.ReadOnlySet; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.draw.css.value.CssPoint2D; import org.jhotdraw8.draw.css.value.CssRectangle2D; @@ -40,6 +38,8 @@ import org.jhotdraw8.fxcollection.typesafekey.MapAccessor; import org.jhotdraw8.geom.FXRectangles; import org.jhotdraw8.geom.FXTransforms; +import org.jhotdraw8.icollection.ChampSet; +import org.jhotdraw8.icollection.readonly.ReadOnlySet; import java.lang.reflect.Field; import java.lang.reflect.Modifier; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/MarkerStrokableFigure.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/MarkerStrokableFigure.java index d0a6d207c..49605c855 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/MarkerStrokableFigure.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/MarkerStrokableFigure.java @@ -11,8 +11,6 @@ import javafx.scene.shape.StrokeType; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.css.converter.CssSizeConverter; import org.jhotdraw8.css.value.CssSize; @@ -22,6 +20,8 @@ import org.jhotdraw8.draw.key.ListStyleableKey; import org.jhotdraw8.draw.key.NullablePaintableStyleableKey; import org.jhotdraw8.draw.key.StrokeStyleableMapAccessor; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.ArrayList; import java.util.Objects; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/PageFigure.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/PageFigure.java index 5630babee..371fed674 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/PageFigure.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/PageFigure.java @@ -22,8 +22,6 @@ import javafx.scene.transform.Transform; import javafx.scene.transform.Translate; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.css.value.DefaultUnitConverter; import org.jhotdraw8.draw.css.value.CssDimension2D; @@ -41,6 +39,8 @@ import org.jhotdraw8.draw.render.RenderingIntent; import org.jhotdraw8.geom.FXRectangles; import org.jhotdraw8.geom.FXTransforms; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.ArrayList; import java.util.List; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/PolygonFigure.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/PolygonFigure.java index 13c9947b7..64373078b 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/PolygonFigure.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/PolygonFigure.java @@ -11,8 +11,6 @@ import javafx.scene.shape.Polygon; import javafx.scene.transform.Transform; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.draw.connector.Connector; import org.jhotdraw8.draw.connector.PathConnector; @@ -27,6 +25,8 @@ import org.jhotdraw8.draw.render.RenderContext; import org.jhotdraw8.geom.FXShapes; import org.jhotdraw8.geom.FXTransforms; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.awt.geom.AffineTransform; import java.awt.geom.PathIterator; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/PolylineFigure.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/PolylineFigure.java index 173563b7c..891329a5a 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/PolylineFigure.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/PolylineFigure.java @@ -11,8 +11,6 @@ import javafx.scene.shape.Polyline; import javafx.scene.transform.Transform; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.draw.css.value.CssPoint2D; import org.jhotdraw8.draw.css.value.CssRectangle2D; @@ -26,6 +24,8 @@ import org.jhotdraw8.fxcollection.typesafekey.NonNullMapAccessor; import org.jhotdraw8.geom.FXShapes; import org.jhotdraw8.geom.FXTransforms; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.awt.geom.AffineTransform; import java.awt.geom.PathIterator; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/SecondStrokableFigure.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/SecondStrokableFigure.java index 9d02cc45f..143ac6cb2 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/SecondStrokableFigure.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/SecondStrokableFigure.java @@ -11,8 +11,6 @@ import javafx.scene.shape.StrokeType; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.css.converter.CssSizeConverter; import org.jhotdraw8.css.value.CssSize; @@ -23,6 +21,8 @@ import org.jhotdraw8.draw.key.NullablePaintableStyleableKey; import org.jhotdraw8.draw.key.StrokeStyleableMapAccessor; import org.jhotdraw8.draw.render.RenderContext; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.ArrayList; import java.util.Objects; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/StrokableFigure.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/StrokableFigure.java index a497bad52..15692f06e 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/StrokableFigure.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/StrokableFigure.java @@ -13,8 +13,6 @@ import javafx.scene.shape.StrokeType; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.css.converter.CssSizeConverter; import org.jhotdraw8.css.value.CssSize; @@ -28,6 +26,8 @@ import org.jhotdraw8.draw.key.StrokeStyleableMapAccessor; import org.jhotdraw8.draw.render.RenderContext; import org.jhotdraw8.geom.FXRectangles; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.awt.*; import java.util.ArrayList; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/StyleableFigure.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/StyleableFigure.java index 29278d1b6..0af5ee1e3 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/StyleableFigure.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/StyleableFigure.java @@ -8,14 +8,14 @@ import javafx.scene.Node; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.ChampSet; -import org.jhotdraw8.collection.readonly.ReadOnlySet; import org.jhotdraw8.draw.key.NullableStringStyleableKey; import org.jhotdraw8.draw.key.StringReadOnlyStyleableKey; import org.jhotdraw8.draw.key.WordSetKey; import org.jhotdraw8.draw.render.RenderContext; import org.jhotdraw8.draw.render.RenderingIntent; import org.jhotdraw8.fxcollection.facade.ObservableSetFacade; +import org.jhotdraw8.icollection.ChampSet; +import org.jhotdraw8.icollection.readonly.ReadOnlySet; /** * {@code StyleableFigure} provides user-editable "id", "style class" and "style" properties, diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/TextStrokeableFigure.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/TextStrokeableFigure.java index 87dbe6a8c..03ad44169 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/TextStrokeableFigure.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/TextStrokeableFigure.java @@ -11,8 +11,6 @@ import javafx.scene.shape.StrokeType; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.css.converter.CssSizeConverter; import org.jhotdraw8.css.value.CssSize; @@ -25,6 +23,8 @@ import org.jhotdraw8.draw.key.NullablePaintableStyleableKey; import org.jhotdraw8.draw.key.StrokeStyleableMapAccessor; import org.jhotdraw8.draw.render.RenderContext; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.ArrayList; import java.util.Objects; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/TransformableFigure.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/TransformableFigure.java index bd20deecb..de0f30a1d 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/TransformableFigure.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/TransformableFigure.java @@ -15,8 +15,6 @@ import javafx.scene.transform.Transform; import javafx.scene.transform.Translate; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.draw.css.converter.CssTranslate3DConverter; import org.jhotdraw8.draw.css.value.CssPoint2D; import org.jhotdraw8.draw.key.CssPoint2DStyleableKey; @@ -30,6 +28,8 @@ import org.jhotdraw8.geom.FXPreciseRotate; import org.jhotdraw8.geom.FXRectangles; import org.jhotdraw8.geom.FXTransforms; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.ArrayList; import java.util.LinkedHashSet; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierControlPointEditHandle.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierControlPointEditHandle.java index cd577a094..4d314a238 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierControlPointEditHandle.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierControlPointEditHandle.java @@ -28,8 +28,6 @@ import javafx.scene.transform.Transform; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.draw.DrawLabels; import org.jhotdraw8.draw.DrawingView; import org.jhotdraw8.draw.css.value.CssColor; @@ -41,6 +39,8 @@ import org.jhotdraw8.geom.Points; import org.jhotdraw8.geom.shape.BezierNode; import org.jhotdraw8.geom.shape.BezierNodePath; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import static org.jhotdraw8.draw.figure.TransformableFigure.ROTATE; import static org.jhotdraw8.draw.figure.TransformableFigure.ROTATION_AXIS; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierNodeEditHandle.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierNodeEditHandle.java index b4c340c90..ac72c6b2b 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierNodeEditHandle.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierNodeEditHandle.java @@ -29,8 +29,6 @@ import javafx.scene.transform.Transform; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.draw.DrawLabels; import org.jhotdraw8.draw.DrawingView; import org.jhotdraw8.draw.css.value.CssColor; @@ -41,6 +39,8 @@ import org.jhotdraw8.geom.Points; import org.jhotdraw8.geom.shape.BezierNode; import org.jhotdraw8.geom.shape.BezierNodePath; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import static org.jhotdraw8.draw.figure.TransformableFigure.ROTATE; import static org.jhotdraw8.draw.figure.TransformableFigure.ROTATION_AXIS; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierNodeMoveHandle.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierNodeMoveHandle.java index 247a5b5aa..a18a8e4fe 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierNodeMoveHandle.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierNodeMoveHandle.java @@ -26,7 +26,6 @@ import javafx.scene.transform.Transform; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.draw.DrawingView; import org.jhotdraw8.draw.css.value.CssPoint2D; import org.jhotdraw8.draw.figure.Figure; @@ -35,6 +34,7 @@ import org.jhotdraw8.geom.FXTransforms; import org.jhotdraw8.geom.Points; import org.jhotdraw8.geom.shape.BezierNode; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.HashSet; import java.util.Set; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierNodeTangentHandle.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierNodeTangentHandle.java index 889d29d47..a97c476dd 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierNodeTangentHandle.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierNodeTangentHandle.java @@ -16,7 +16,6 @@ import javafx.scene.transform.Transform; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.draw.DrawingView; import org.jhotdraw8.draw.css.value.CssColor; import org.jhotdraw8.draw.figure.Figure; @@ -24,6 +23,7 @@ import org.jhotdraw8.geom.FXTransforms; import org.jhotdraw8.geom.Points; import org.jhotdraw8.geom.shape.BezierNode; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.List; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierPathEditHandle.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierPathEditHandle.java index 29dad7f46..d8a33edd1 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierPathEditHandle.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierPathEditHandle.java @@ -9,8 +9,6 @@ import javafx.scene.control.MenuItem; import javafx.scene.input.MouseEvent; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.draw.DrawLabels; import org.jhotdraw8.draw.DrawingView; import org.jhotdraw8.draw.figure.Figure; @@ -19,6 +17,8 @@ import org.jhotdraw8.geom.intersect.IntersectionResult; import org.jhotdraw8.geom.shape.BezierNode; import org.jhotdraw8.geom.shape.BezierNodePath; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; public class BezierPathEditHandle extends BezierPathOutlineHandle { private final MapAccessor> pointKey; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierPathOutlineHandle.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierPathOutlineHandle.java index 8f5717203..17635d732 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierPathOutlineHandle.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/BezierPathOutlineHandle.java @@ -14,7 +14,6 @@ import javafx.scene.transform.Transform; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.draw.DrawingView; import org.jhotdraw8.draw.css.value.CssColor; import org.jhotdraw8.draw.css.value.Paintable; @@ -26,6 +25,7 @@ import org.jhotdraw8.geom.SvgPaths; import org.jhotdraw8.geom.shape.BezierNode; import org.jhotdraw8.geom.shape.BezierNodePath; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.ArrayList; import java.util.List; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/PolyPointEditHandle.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/PolyPointEditHandle.java index 5816c588c..af2b165fb 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/PolyPointEditHandle.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/PolyPointEditHandle.java @@ -23,7 +23,6 @@ import javafx.scene.transform.Transform; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.draw.DrawLabels; import org.jhotdraw8.draw.DrawingView; import org.jhotdraw8.draw.css.value.CssColor; @@ -32,6 +31,7 @@ import org.jhotdraw8.fxcollection.typesafekey.NonNullMapAccessor; import org.jhotdraw8.geom.FXTransforms; import org.jhotdraw8.geom.Points; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.function.Function; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/PolyPointMoveHandle.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/PolyPointMoveHandle.java index 4c5468d78..000496ecf 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/PolyPointMoveHandle.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/PolyPointMoveHandle.java @@ -19,7 +19,6 @@ import javafx.scene.transform.Transform; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.draw.DrawingView; import org.jhotdraw8.draw.css.value.CssColor; import org.jhotdraw8.draw.css.value.CssPoint2D; @@ -28,6 +27,7 @@ import org.jhotdraw8.fxcollection.typesafekey.MapAccessor; import org.jhotdraw8.geom.FXTransforms; import org.jhotdraw8.geom.Points; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.HashSet; import java.util.Set; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/PolygonOutlineHandle.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/PolygonOutlineHandle.java index 34d6fe84e..66b09f158 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/PolygonOutlineHandle.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/PolygonOutlineHandle.java @@ -18,7 +18,6 @@ import javafx.scene.transform.Transform; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.draw.DrawLabels; import org.jhotdraw8.draw.DrawingView; import org.jhotdraw8.draw.css.value.CssColor; @@ -35,6 +34,7 @@ import org.jhotdraw8.geom.intersect.IntersectionResult; import org.jhotdraw8.geom.intersect.IntersectionResultEx; import org.jhotdraw8.geom.intersect.IntersectionStatus; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.awt.geom.PathIterator; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/PolylineOutlineHandle.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/PolylineOutlineHandle.java index f9611c806..13b6ce212 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/PolylineOutlineHandle.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/PolylineOutlineHandle.java @@ -18,7 +18,6 @@ import javafx.scene.transform.Transform; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.draw.DrawLabels; import org.jhotdraw8.draw.DrawingView; import org.jhotdraw8.draw.css.value.CssColor; @@ -35,6 +34,7 @@ import org.jhotdraw8.geom.intersect.IntersectionResult; import org.jhotdraw8.geom.intersect.IntersectionResultEx; import org.jhotdraw8.geom.intersect.IntersectionStatus; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.awt.geom.PathIterator; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/TransformHandleKit.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/TransformHandleKit.java index 53c674461..33e052593 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/TransformHandleKit.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/handle/TransformHandleKit.java @@ -21,8 +21,6 @@ import javafx.scene.transform.Translate; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.draw.DrawingView; import org.jhotdraw8.draw.css.value.CssPoint2D; import org.jhotdraw8.draw.css.value.CssRectangle2D; @@ -32,6 +30,8 @@ import org.jhotdraw8.draw.locator.Locator; import org.jhotdraw8.draw.model.DrawingModel; import org.jhotdraw8.geom.FXTransforms; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.Collection; import java.util.function.Function; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/inspector/HierarchyInspector.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/inspector/HierarchyInspector.java index 560b94a33..3a2ec8f59 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/inspector/HierarchyInspector.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/inspector/HierarchyInspector.java @@ -29,8 +29,6 @@ import org.jhotdraw8.application.EditableComponent; import org.jhotdraw8.base.text.CachingCollator; import org.jhotdraw8.base.text.NaturalSortCollator; -import org.jhotdraw8.collection.ChampSet; -import org.jhotdraw8.collection.immutable.ImmutableSet; import org.jhotdraw8.draw.DrawingView; import org.jhotdraw8.draw.figure.Figure; import org.jhotdraw8.draw.figure.HideableFigure; @@ -45,6 +43,8 @@ import org.jhotdraw8.fxbase.tree.ExpandedTreeItemIterator; import org.jhotdraw8.fxbase.tree.SimpleTreePresentationModel; import org.jhotdraw8.fxbase.tree.TreePresentationModel; +import org.jhotdraw8.icollection.ChampSet; +import org.jhotdraw8.icollection.immutable.ImmutableSet; import org.jhotdraw8.xml.converter.XmlWordListConverter; import org.jhotdraw8.xml.converter.XmlWordSetConverter; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/inspector/StyleClassesInspector.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/inspector/StyleClassesInspector.java index b03de7960..01e0af357 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/inspector/StyleClassesInspector.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/inspector/StyleClassesInspector.java @@ -20,8 +20,6 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.event.Listener; -import org.jhotdraw8.collection.ChampSet; -import org.jhotdraw8.collection.immutable.ImmutableSet; import org.jhotdraw8.draw.DrawingView; import org.jhotdraw8.draw.figure.Figure; import org.jhotdraw8.draw.figure.StyleableFigure; @@ -30,6 +28,8 @@ import org.jhotdraw8.draw.model.DrawingModelEvent; import org.jhotdraw8.fxbase.concurrent.PlatformUtil; import org.jhotdraw8.fxcollection.typesafekey.Key; +import org.jhotdraw8.icollection.ChampSet; +import org.jhotdraw8.icollection.immutable.ImmutableSet; import java.io.IOException; import java.io.InputStream; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/inspector/StylesheetsInspector.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/inspector/StylesheetsInspector.java index 7d28fe90a..fa44a04e2 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/inspector/StylesheetsInspector.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/inspector/StylesheetsInspector.java @@ -26,8 +26,6 @@ import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.application.action.file.BrowseFileDirectoryAction; import org.jhotdraw8.base.converter.SimpleUriResolver; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.draw.DrawingView; import org.jhotdraw8.draw.figure.Drawing; import org.jhotdraw8.draw.figure.Figure; @@ -35,6 +33,8 @@ import org.jhotdraw8.fxbase.concurrent.PlatformUtil; import org.jhotdraw8.fxbase.control.ListViewUtil; import org.jhotdraw8.fxbase.converter.StringConverterAdapter; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import org.jhotdraw8.xml.converter.XmlUriConverter; import java.io.File; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/AbstractExportOutputFormat.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/AbstractExportOutputFormat.java index b306e16dd..adad90080 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/AbstractExportOutputFormat.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/AbstractExportOutputFormat.java @@ -12,8 +12,6 @@ import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.IdFactory; import org.jhotdraw8.base.converter.SimpleIdFactory; -import org.jhotdraw8.collection.ChampMap; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.draw.figure.Drawing; import org.jhotdraw8.draw.figure.Figure; import org.jhotdraw8.draw.figure.Page; @@ -22,6 +20,8 @@ import org.jhotdraw8.draw.render.RenderingIntent; import org.jhotdraw8.draw.render.SimpleDrawingRenderer; import org.jhotdraw8.fxcollection.typesafekey.Key; +import org.jhotdraw8.icollection.ChampMap; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.io.IOException; import java.nio.file.Path; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/AbstractInputFormat.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/AbstractInputFormat.java index 059812a10..3f22ca35b 100644 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/AbstractInputFormat.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/AbstractInputFormat.java @@ -6,9 +6,9 @@ package org.jhotdraw8.draw.io; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.ChampMap; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.fxcollection.typesafekey.Key; +import org.jhotdraw8.icollection.ChampMap; +import org.jhotdraw8.icollection.immutable.ImmutableMap; public abstract class AbstractInputFormat implements InputFormat { private @NonNull ImmutableMap, Object> options = ChampMap.of(); diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/DefaultFigureFactory.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/DefaultFigureFactory.java index 07e752f3f..070bd4e87 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/DefaultFigureFactory.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/DefaultFigureFactory.java @@ -25,7 +25,6 @@ import org.jhotdraw8.base.converter.DefaultConverter; import org.jhotdraw8.base.converter.IdFactory; import org.jhotdraw8.base.text.RegexReplace; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.css.converter.CssDoubleConverter; import org.jhotdraw8.css.converter.CssKebabCaseEnumConverter; @@ -97,6 +96,7 @@ import org.jhotdraw8.draw.xml.converter.XmlRectangle2DConverter; import org.jhotdraw8.draw.xml.converter.XmlSvgPathConverter; import org.jhotdraw8.fxcollection.typesafekey.MapAccessor; +import org.jhotdraw8.icollection.immutable.ImmutableList; import org.jhotdraw8.xml.converter.XmlBooleanConverter; import org.jhotdraw8.xml.converter.XmlObjectReferenceConverter; import org.jhotdraw8.xml.converter.XmlUriConverter; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/ExportOutputFormat.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/ExportOutputFormat.java index 8699454f6..c5dfcfbb0 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/ExportOutputFormat.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/ExportOutputFormat.java @@ -5,9 +5,9 @@ package org.jhotdraw8.draw.io; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.SimpleNonNullKey; +import org.jhotdraw8.icollection.immutable.ImmutableMap; /** * ExportOutputFormat. diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/FigureFactory.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/FigureFactory.java index 57ad2a552..54e40c1f5 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/FigureFactory.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/FigureFactory.java @@ -6,10 +6,10 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.draw.figure.Drawing; import org.jhotdraw8.draw.figure.Figure; import org.jhotdraw8.fxcollection.typesafekey.MapAccessor; +import org.jhotdraw8.icollection.immutable.ImmutableList; import org.w3c.dom.Node; import javax.xml.stream.XMLStreamException; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/InputFormat.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/InputFormat.java index d77ced1af..a8f2d1279 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/InputFormat.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/InputFormat.java @@ -6,11 +6,11 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.draw.figure.Drawing; import org.jhotdraw8.draw.figure.Figure; import org.jhotdraw8.fxbase.concurrent.WorkState; import org.jhotdraw8.fxcollection.typesafekey.Key; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.io.BufferedInputStream; import java.io.IOException; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/OutputFormat.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/OutputFormat.java index fa0c6e554..cc376f998 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/OutputFormat.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/OutputFormat.java @@ -6,10 +6,10 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.draw.figure.Drawing; import org.jhotdraw8.fxbase.concurrent.WorkState; import org.jhotdraw8.fxcollection.typesafekey.Key; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.io.BufferedOutputStream; import java.io.IOException; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/SimpleXmlStaxReader.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/SimpleXmlStaxReader.java index 850f3e591..e015a338c 100644 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/SimpleXmlStaxReader.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/SimpleXmlStaxReader.java @@ -10,8 +10,6 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.IdFactory; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.draw.figure.Drawing; import org.jhotdraw8.draw.figure.Figure; import org.jhotdraw8.draw.figure.Layer; @@ -21,6 +19,8 @@ import org.jhotdraw8.fxbase.concurrent.SimpleWorkState; import org.jhotdraw8.fxbase.concurrent.WorkState; import org.jhotdraw8.fxcollection.typesafekey.MapAccessor; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import javax.xml.stream.Location; import javax.xml.stream.XMLInputFactory; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/SimpleXmlWriter.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/SimpleXmlWriter.java index e45fca53a..4d7c71f0b 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/SimpleXmlWriter.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/SimpleXmlWriter.java @@ -9,9 +9,6 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.IdFactory; -import org.jhotdraw8.collection.ChampMap; -import org.jhotdraw8.collection.immutable.ImmutableList; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.draw.figure.Clipping; import org.jhotdraw8.draw.figure.ClippingFigure; import org.jhotdraw8.draw.figure.Drawing; @@ -22,6 +19,9 @@ import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.MapAccessor; import org.jhotdraw8.fxcollection.typesafekey.SimpleNonNullKey; +import org.jhotdraw8.icollection.ChampMap; +import org.jhotdraw8.icollection.immutable.ImmutableList; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import org.jhotdraw8.xml.IndentingXMLStreamWriter; import org.w3c.dom.Document; import org.xml.sax.InputSource; @@ -33,10 +33,20 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import javax.xml.transform.dom.DOMResult; -import java.io.*; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; import java.net.URI; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; /** * SimpleXmlWriter. diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/XmlEncoderOutputFormat.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/XmlEncoderOutputFormat.java index 5e3bc5ee2..29239fcc7 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/XmlEncoderOutputFormat.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/io/XmlEncoderOutputFormat.java @@ -6,11 +6,11 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.ChampMap; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.draw.figure.Drawing; import org.jhotdraw8.fxbase.concurrent.WorkState; import org.jhotdraw8.fxcollection.typesafekey.Key; +import org.jhotdraw8.icollection.ChampMap; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.beans.XMLEncoder; import java.io.IOException; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/BezierNodeListStyleableKey.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/BezierNodeListStyleableKey.java index 3c551f619..0d2797912 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/BezierNodeListStyleableKey.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/BezierNodeListStyleableKey.java @@ -6,13 +6,13 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.draw.css.converter.CssBezierNodeListConverter; import org.jhotdraw8.fxbase.styleable.WritableStyleableMapAccessor; import org.jhotdraw8.fxcollection.typesafekey.NonNullKey; import org.jhotdraw8.geom.shape.BezierNode; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.io.Serial; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/BoundingBoxMapAccessor.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/BoundingBoxMapAccessor.java index 80137c242..131b49fcd 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/BoundingBoxMapAccessor.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/BoundingBoxMapAccessor.java @@ -7,9 +7,9 @@ import javafx.geometry.BoundingBox; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.MapAccessor; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.io.Serial; import java.util.Map; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/BoundingBoxStyleableMapAccessor.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/BoundingBoxStyleableMapAccessor.java index ad638e431..f21fa7979 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/BoundingBoxStyleableMapAccessor.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/BoundingBoxStyleableMapAccessor.java @@ -8,10 +8,10 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.draw.css.converter.CssBoundingBoxConverter; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.MapAccessor; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.io.Serial; import java.util.Map; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/CssInsetsStyleableMapAccessor.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/CssInsetsStyleableMapAccessor.java index 07d43480b..ca3b96560 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/CssInsetsStyleableMapAccessor.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/CssInsetsStyleableMapAccessor.java @@ -7,12 +7,12 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.draw.css.converter.CssInsetsConverter; import org.jhotdraw8.draw.css.value.CssInsets; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.NonNullMapAccessor; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.io.Serial; import java.util.Map; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/CssPoint2DStyleableMapAccessor.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/CssPoint2DStyleableMapAccessor.java index 76ac26eb0..696d51dd4 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/CssPoint2DStyleableMapAccessor.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/CssPoint2DStyleableMapAccessor.java @@ -7,12 +7,12 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.draw.css.converter.CssPoint2DConverter; import org.jhotdraw8.draw.css.value.CssPoint2D; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.NonNullMapAccessor; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.io.Serial; import java.util.Map; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/CssRectangle2DStyleableMapAccessor.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/CssRectangle2DStyleableMapAccessor.java index f15952bdd..78fd77572 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/CssRectangle2DStyleableMapAccessor.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/CssRectangle2DStyleableMapAccessor.java @@ -7,12 +7,12 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.draw.css.converter.CssRectangle2DConverter; import org.jhotdraw8.draw.css.value.CssRectangle2D; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.NonNullMapAccessor; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.io.Serial; import java.util.Map; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/DoubleListStyleableKey.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/DoubleListStyleableKey.java index 025cb7dc2..a1339f5f7 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/DoubleListStyleableKey.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/DoubleListStyleableKey.java @@ -6,11 +6,11 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.css.converter.CssDoubleConverter; import org.jhotdraw8.css.converter.CssListConverter; import org.jhotdraw8.fxbase.styleable.WritableStyleableMapAccessor; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.io.Serial; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/EffectStyleableKey.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/EffectStyleableKey.java index bd3a43179..5b7008c3c 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/EffectStyleableKey.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/EffectStyleableKey.java @@ -7,9 +7,9 @@ import javafx.scene.effect.Effect; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.draw.css.converter.CssEffectConverter; import org.jhotdraw8.fxbase.styleable.WritableStyleableMapAccessor; +import org.jhotdraw8.icollection.immutable.ImmutableList; /** * EffectStyleableKey. diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/FontStyleableMapAccessor.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/FontStyleableMapAccessor.java index 212a15a26..29e3df9ad 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/FontStyleableMapAccessor.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/FontStyleableMapAccessor.java @@ -9,13 +9,13 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.draw.css.converter.CssFontConverter; import org.jhotdraw8.draw.css.value.CssFont; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.MapAccessor; import org.jhotdraw8.fxcollection.typesafekey.NonNullMapAccessor; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.io.Serial; import java.util.Map; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/InsetsStyleableMapAccessor.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/InsetsStyleableMapAccessor.java index f4172dc4c..c16896e81 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/InsetsStyleableMapAccessor.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/InsetsStyleableMapAccessor.java @@ -8,10 +8,10 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.draw.css.converter.InsetsConverter; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.MapAccessor; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.io.Serial; import java.util.Map; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/ListStyleableKey.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/ListStyleableKey.java index df720d7b5..b21ccbf56 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/ListStyleableKey.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/ListStyleableKey.java @@ -6,13 +6,13 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.css.converter.CssConverter; import org.jhotdraw8.css.converter.CssListConverter; import org.jhotdraw8.fxbase.styleable.WritableStyleableMapAccessor; import org.jhotdraw8.fxcollection.typesafekey.NonNullKey; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.io.Serial; import java.lang.reflect.Type; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/NullableBezierNodeListStyleableKey.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/NullableBezierNodeListStyleableKey.java index 1260905e8..e4d09a32c 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/NullableBezierNodeListStyleableKey.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/NullableBezierNodeListStyleableKey.java @@ -7,11 +7,11 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.draw.css.converter.CssBezierNodeListConverter; import org.jhotdraw8.fxbase.styleable.WritableStyleableMapAccessor; import org.jhotdraw8.geom.shape.BezierNode; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.io.Serial; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/NullableCssRectangle2DStyleableMapAccessor.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/NullableCssRectangle2DStyleableMapAccessor.java index 898371993..626502790 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/NullableCssRectangle2DStyleableMapAccessor.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/NullableCssRectangle2DStyleableMapAccessor.java @@ -7,12 +7,12 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.draw.css.converter.CssRectangle2DConverter; import org.jhotdraw8.draw.css.value.CssRectangle2D; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.MapAccessor; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.io.Serial; import java.util.Map; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/NullableFXPathElementsStyleableKey.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/NullableFXPathElementsStyleableKey.java index 0fcd9ed0a..580cfd2be 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/NullableFXPathElementsStyleableKey.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/NullableFXPathElementsStyleableKey.java @@ -8,10 +8,10 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.draw.css.converter.CssFXPathElementsConverter; import org.jhotdraw8.fxbase.styleable.WritableStyleableMapAccessor; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.io.Serial; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/NullableListStyleableKey.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/NullableListStyleableKey.java index 2f0574dad..0f831015b 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/NullableListStyleableKey.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/NullableListStyleableKey.java @@ -6,13 +6,13 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.css.converter.CssConverter; import org.jhotdraw8.css.converter.CssListConverter; import org.jhotdraw8.fxbase.styleable.WritableStyleableMapAccessor; import org.jhotdraw8.fxcollection.typesafekey.NullableKey; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.io.Serial; import java.lang.reflect.Type; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/NullableSetStyleableKey.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/NullableSetStyleableKey.java index 375811146..d16befc4a 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/NullableSetStyleableKey.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/NullableSetStyleableKey.java @@ -6,12 +6,12 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorSet; -import org.jhotdraw8.collection.immutable.ImmutableSequencedSet; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.css.converter.CssConverter; import org.jhotdraw8.fxbase.styleable.WritableStyleableMapAccessor; import org.jhotdraw8.fxcollection.typesafekey.NullableKey; +import org.jhotdraw8.icollection.VectorSet; +import org.jhotdraw8.icollection.immutable.ImmutableSequencedSet; import java.io.Serial; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/PaperSizeStyleableMapAccessor.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/PaperSizeStyleableMapAccessor.java index f9837a45c..c522672f5 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/PaperSizeStyleableMapAccessor.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/PaperSizeStyleableMapAccessor.java @@ -7,13 +7,13 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.draw.css.converter.CssPaperSizeConverter; import org.jhotdraw8.draw.css.value.CssDimension2D; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.MapAccessor; import org.jhotdraw8.fxcollection.typesafekey.NonNullMapAccessor; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.io.Serial; import java.util.Map; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Point2DListStyleableKey.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Point2DListStyleableKey.java index 398936aec..aaddf3e34 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Point2DListStyleableKey.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Point2DListStyleableKey.java @@ -7,13 +7,13 @@ import javafx.geometry.Point2D; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.css.converter.CssListConverter; import org.jhotdraw8.draw.css.converter.Point2DConverter; import org.jhotdraw8.fxbase.styleable.WritableStyleableMapAccessor; import org.jhotdraw8.fxcollection.typesafekey.NonNullKey; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.io.Serial; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Point2DStyleableMapAccessor.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Point2DStyleableMapAccessor.java index 442f24194..fcdeb7408 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Point2DStyleableMapAccessor.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Point2DStyleableMapAccessor.java @@ -8,11 +8,11 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.draw.css.converter.Point2DConverter; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.MapAccessor; import org.jhotdraw8.fxcollection.typesafekey.NonNullMapAccessor; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.io.Serial; import java.util.Map; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Point3DStyleableMapAccessor.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Point3DStyleableMapAccessor.java index ab954d072..dd79648f8 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Point3DStyleableMapAccessor.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Point3DStyleableMapAccessor.java @@ -8,11 +8,11 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.draw.css.converter.Point3DConverter; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.MapAccessor; import org.jhotdraw8.fxcollection.typesafekey.NonNullMapAccessor; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.io.Serial; import java.util.Map; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Rectangle2DMapAccessor.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Rectangle2DMapAccessor.java index 4604aa0d1..2ad603ccc 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Rectangle2DMapAccessor.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Rectangle2DMapAccessor.java @@ -7,9 +7,9 @@ import javafx.geometry.Rectangle2D; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.MapAccessor; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.io.Serial; import java.util.Map; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Rectangle2DStyleableMapAccessor.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Rectangle2DStyleableMapAccessor.java index 7f21572c9..45650a31f 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Rectangle2DStyleableMapAccessor.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Rectangle2DStyleableMapAccessor.java @@ -8,10 +8,10 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.draw.css.converter.Rectangle2DConverter; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.NonNullMapAccessor; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.io.Serial; import java.util.Map; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Scale2DStyleableMapAccessor.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Scale2DStyleableMapAccessor.java index 29f0655c2..9eef3e49d 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Scale2DStyleableMapAccessor.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Scale2DStyleableMapAccessor.java @@ -8,10 +8,10 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.draw.css.converter.CssScale2DConverter; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.MapAccessor; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.io.Serial; import java.util.Map; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Scale3DStyleableMapAccessor.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Scale3DStyleableMapAccessor.java index 48e48918d..70fbeed54 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Scale3DStyleableMapAccessor.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/Scale3DStyleableMapAccessor.java @@ -8,11 +8,11 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.draw.css.converter.CssScale3DConverter; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.MapAccessor; import org.jhotdraw8.fxcollection.typesafekey.NonNullMapAccessor; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.io.Serial; import java.util.Map; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/SetStyleableKey.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/SetStyleableKey.java index 460573765..9e4c3101b 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/SetStyleableKey.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/SetStyleableKey.java @@ -5,12 +5,12 @@ package org.jhotdraw8.draw.key; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorSet; -import org.jhotdraw8.collection.immutable.ImmutableSequencedSet; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.css.converter.CssConverter; import org.jhotdraw8.fxbase.styleable.WritableStyleableMapAccessor; import org.jhotdraw8.fxcollection.typesafekey.NonNullKey; +import org.jhotdraw8.icollection.VectorSet; +import org.jhotdraw8.icollection.immutable.ImmutableSequencedSet; import java.io.Serial; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/StrokeStyleableMapAccessor.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/StrokeStyleableMapAccessor.java index 748978f04..977a9a91a 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/StrokeStyleableMapAccessor.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/StrokeStyleableMapAccessor.java @@ -10,13 +10,13 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.immutable.ImmutableList; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.draw.css.converter.CssStrokeStyleConverter; import org.jhotdraw8.draw.css.value.CssStrokeStyle; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.MapAccessor; +import org.jhotdraw8.icollection.immutable.ImmutableList; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.io.Serial; import java.util.Map; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/SymmetricCssPoint2DStyleableMapAccessor.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/SymmetricCssPoint2DStyleableMapAccessor.java index 1392df8e3..05671a8ee 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/SymmetricCssPoint2DStyleableMapAccessor.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/SymmetricCssPoint2DStyleableMapAccessor.java @@ -7,12 +7,12 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.draw.css.converter.CssSymmetricCssPoint2DConverter; import org.jhotdraw8.draw.css.value.CssPoint2D; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.NonNullMapAccessor; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import java.io.Serial; import java.util.Map; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/TransformListStyleableKey.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/TransformListStyleableKey.java index 2f2f554a6..cad30b6b7 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/TransformListStyleableKey.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/TransformListStyleableKey.java @@ -7,13 +7,13 @@ import javafx.scene.transform.Transform; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.css.converter.CssListConverter; import org.jhotdraw8.draw.css.converter.CssTransformConverter; import org.jhotdraw8.fxbase.styleable.WritableStyleableMapAccessor; import org.jhotdraw8.fxcollection.typesafekey.NonNullKey; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.io.Serial; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/WordSetKey.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/WordSetKey.java index 3a9c43672..2b898ca91 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/WordSetKey.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/WordSetKey.java @@ -5,9 +5,9 @@ package org.jhotdraw8.draw.key; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableSet; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.fxcollection.typesafekey.SimpleNonNullKey; +import org.jhotdraw8.icollection.immutable.ImmutableSet; import java.io.Serial; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/WordSetStyleableKey.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/WordSetStyleableKey.java index f3030cf88..090a303da 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/WordSetStyleableKey.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/key/WordSetStyleableKey.java @@ -5,12 +5,12 @@ package org.jhotdraw8.draw.key; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorSet; -import org.jhotdraw8.collection.immutable.ImmutableSequencedSet; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.css.converter.CssConverter; import org.jhotdraw8.css.converter.CssSetConverter; import org.jhotdraw8.draw.css.converter.CssIdentConverter; +import org.jhotdraw8.icollection.VectorSet; +import org.jhotdraw8.icollection.immutable.ImmutableSequencedSet; import java.io.Serial; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/popup/ExamplesPicker.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/popup/ExamplesPicker.java index d054cbf8e..aad731ebc 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/popup/ExamplesPicker.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/popup/ExamplesPicker.java @@ -11,9 +11,9 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.application.resources.Resources; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.converter.CssConverter; import org.jhotdraw8.draw.DrawLabels; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.io.IOException; import java.text.ParseException; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/BezierCreationTool.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/BezierCreationTool.java index 2407a3e18..9ff23bb43 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/BezierCreationTool.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/BezierCreationTool.java @@ -11,8 +11,6 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.application.resources.Resources; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.draw.DrawingEditor; import org.jhotdraw8.draw.DrawingView; import org.jhotdraw8.draw.css.value.CssPoint2D; @@ -26,6 +24,8 @@ import org.jhotdraw8.geom.FXTransforms; import org.jhotdraw8.geom.shape.BezierNode; import org.jhotdraw8.geom.shape.BezierNodePathBuilder; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.ArrayList; import java.util.List; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/PolyCreationTool.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/PolyCreationTool.java index 8c802e1a3..980fb9f5b 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/PolyCreationTool.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/PolyCreationTool.java @@ -10,7 +10,6 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.application.resources.Resources; -import org.jhotdraw8.collection.VectorList; import org.jhotdraw8.draw.DrawingEditor; import org.jhotdraw8.draw.DrawingView; import org.jhotdraw8.draw.css.value.CssPoint2D; @@ -20,6 +19,7 @@ import org.jhotdraw8.draw.handle.HandleType; import org.jhotdraw8.draw.key.Point2DListStyleableKey; import org.jhotdraw8.draw.model.DrawingModel; +import org.jhotdraw8.icollection.VectorList; import java.util.ArrayList; import java.util.Objects; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/xml/converter/XmlBezierNodeListConverter.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/xml/converter/XmlBezierNodeListConverter.java index 02293ec60..6dbdaffed 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/xml/converter/XmlBezierNodeListConverter.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/xml/converter/XmlBezierNodeListConverter.java @@ -10,14 +10,14 @@ import org.jhotdraw8.base.converter.IdResolver; import org.jhotdraw8.base.converter.IdSupplier; import org.jhotdraw8.base.io.CharBufferReader; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.parser.CssTokenType; import org.jhotdraw8.css.parser.StreamCssTokenizer; import org.jhotdraw8.geom.SvgPaths; import org.jhotdraw8.geom.shape.BezierNode; import org.jhotdraw8.geom.shape.BezierNodePath; import org.jhotdraw8.geom.shape.BezierNodePathBuilder; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.io.IOException; import java.nio.CharBuffer; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/xml/converter/XmlFXSvgPathConverter.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/xml/converter/XmlFXSvgPathConverter.java index ba0aca82d..7e4df8bb8 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/xml/converter/XmlFXSvgPathConverter.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/xml/converter/XmlFXSvgPathConverter.java @@ -10,9 +10,9 @@ import org.jhotdraw8.base.converter.Converter; import org.jhotdraw8.base.converter.IdResolver; import org.jhotdraw8.base.converter.IdSupplier; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.geom.FXSvgPaths; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.io.IOException; import java.nio.CharBuffer; diff --git a/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/AbstractCompositeFigureTest.java b/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/AbstractCompositeFigureTest.java index 7117f7fa9..bb44b1f5f 100755 --- a/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/AbstractCompositeFigureTest.java +++ b/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/AbstractCompositeFigureTest.java @@ -9,13 +9,13 @@ import javafx.scene.Node; import javafx.scene.transform.Transform; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.readonly.ReadOnlySet; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.draw.figure.AbstractCompositeFigure; import org.jhotdraw8.draw.figure.Figure; import org.jhotdraw8.draw.figure.NonTransformableFigure; import org.jhotdraw8.draw.render.RenderContext; import org.jhotdraw8.fxbase.styleable.StyleableBean; +import org.jhotdraw8.icollection.readonly.ReadOnlySet; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssListConverterTest.java b/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssListConverterTest.java index fccd23684..bfcdc3506 100755 --- a/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssListConverterTest.java +++ b/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssListConverterTest.java @@ -8,11 +8,11 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.IdFactory; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.converter.CssDoubleConverter; import org.jhotdraw8.css.converter.CssListConverter; import org.jhotdraw8.css.converter.CssStringConverter; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.TestFactory; diff --git a/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssStrokeConverterTest.java b/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssStrokeConverterTest.java index bbae5633e..2643c6a2c 100755 --- a/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssStrokeConverterTest.java +++ b/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/CssStrokeConverterTest.java @@ -10,10 +10,10 @@ import javafx.scene.shape.StrokeType; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.base.converter.IdFactory; -import org.jhotdraw8.collection.VectorList; import org.jhotdraw8.css.parser.CssTokenType; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.draw.css.value.CssStrokeStyle; +import org.jhotdraw8.icollection.VectorList; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.TestFactory; diff --git a/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/model/FigureSelectorModelTest.java b/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/model/FigureSelectorModelTest.java index 792c016c6..63848db3d 100755 --- a/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/model/FigureSelectorModelTest.java +++ b/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/model/FigureSelectorModelTest.java @@ -6,13 +6,13 @@ import javafx.css.StyleOrigin; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.VectorList; import org.jhotdraw8.css.parser.CssToken; import org.jhotdraw8.css.parser.CssTokenType; import org.jhotdraw8.draw.css.value.Paintable; import org.jhotdraw8.draw.figure.FillableFigure; import org.jhotdraw8.draw.figure.LabelFigure; import org.jhotdraw8.draw.key.NullablePaintableStyleableKey; +import org.jhotdraw8.icollection.VectorList; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/function/AbstractCssFunctionProcessorTest.java b/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/function/AbstractCssFunctionProcessorTest.java index bf2330233..e6453cf29 100644 --- a/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/function/AbstractCssFunctionProcessorTest.java +++ b/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/function/AbstractCssFunctionProcessorTest.java @@ -6,13 +6,13 @@ package org.jhotdraw8.draw.css.value.function; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.manager.CssFunctionProcessor; import org.jhotdraw8.css.model.DocumentSelectorModel; import org.jhotdraw8.css.parser.CssToken; import org.jhotdraw8.css.parser.CssTokenType; import org.jhotdraw8.css.parser.StreamCssTokenizer; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.InputSource; diff --git a/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/function/LadderCssFunctionTest.java b/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/function/LadderCssFunctionTest.java index bf9c9d1f2..456bc5474 100755 --- a/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/function/LadderCssFunctionTest.java +++ b/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/function/LadderCssFunctionTest.java @@ -6,7 +6,6 @@ package org.jhotdraw8.draw.css.value.function; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.function.CssFunction; import org.jhotdraw8.css.function.VarCssFunction; import org.jhotdraw8.css.manager.CssFunctionProcessor; @@ -14,6 +13,7 @@ import org.jhotdraw8.css.model.DocumentSelectorModel; import org.jhotdraw8.css.parser.CssToken; import org.jhotdraw8.draw.css.function.LadderCssFunction; +import org.jhotdraw8.icollection.immutable.ImmutableList; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.TestFactory; import org.w3c.dom.Element; diff --git a/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/FigureTest.java b/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/FigureTest.java index 00820484a..dddaa13a7 100755 --- a/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/FigureTest.java +++ b/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/draw/figure/FigureTest.java @@ -16,8 +16,6 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.event.Listener; -import org.jhotdraw8.collection.ChampSet; -import org.jhotdraw8.collection.readonly.ReadOnlySet; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.draw.connector.Connector; import org.jhotdraw8.draw.css.value.CssRectangle2D; @@ -26,6 +24,8 @@ import org.jhotdraw8.fxbase.styleable.StyleableBean; import org.jhotdraw8.fxcollection.typesafekey.MapAccessor; import org.jhotdraw8.geom.FXTransforms; +import org.jhotdraw8.icollection.ChampSet; +import org.jhotdraw8.icollection.readonly.ReadOnlySet; import org.junit.jupiter.api.Test; import java.util.Collections; diff --git a/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/styleable/AbstractStyleablePropertyBeanTest.java b/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/styleable/AbstractStyleablePropertyBeanTest.java index ca0a5fbe2..97dd9101d 100755 --- a/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/styleable/AbstractStyleablePropertyBeanTest.java +++ b/org.jhotdraw8.draw/src/test/java/org.jhotdraw8.draw/org/jhotdraw8/styleable/AbstractStyleablePropertyBeanTest.java @@ -6,11 +6,11 @@ import javafx.beans.property.ReadOnlyProperty; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.readonly.ReadOnlySet; import org.jhotdraw8.draw.figure.FillableFigure; import org.jhotdraw8.draw.key.NullablePaintableStyleableKey; import org.jhotdraw8.fxbase.styleable.AbstractStyleablePropertyBean; import org.jhotdraw8.fxbase.styleable.StyleableBean; +import org.jhotdraw8.icollection.readonly.ReadOnlySet; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/org.jhotdraw8.examples/src/main/java/org.jhotdraw8.examples/org/jhotdraw8/examples/mini/CssExample.java b/org.jhotdraw8.examples/src/main/java/org.jhotdraw8.examples/org/jhotdraw8/examples/mini/CssExample.java index 0eb19aa3f..3ff3c371b 100755 --- a/org.jhotdraw8.examples/src/main/java/org.jhotdraw8.examples/org/jhotdraw8/examples/mini/CssExample.java +++ b/org.jhotdraw8.examples/src/main/java/org.jhotdraw8.examples/org/jhotdraw8/examples/mini/CssExample.java @@ -9,7 +9,6 @@ import javafx.scene.control.ScrollPane; import javafx.stage.Stage; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorList; import org.jhotdraw8.draw.DrawingEditor; import org.jhotdraw8.draw.DrawingView; import org.jhotdraw8.draw.SimpleDrawingEditor; @@ -27,6 +26,7 @@ import org.jhotdraw8.draw.render.SimpleRenderContext; import org.jhotdraw8.draw.tool.SelectionTool; import org.jhotdraw8.draw.tool.Tool; +import org.jhotdraw8.icollection.VectorList; import java.net.URI; import java.util.ArrayList; diff --git a/org.jhotdraw8.fxbase/src/main/java/org.jhotdraw8.fxbase/org/jhotdraw8/fxbase/styleable/StyleableBean.java b/org.jhotdraw8.fxbase/src/main/java/org.jhotdraw8.fxbase/org/jhotdraw8/fxbase/styleable/StyleableBean.java index 7782aed21..bd82d0f42 100644 --- a/org.jhotdraw8.fxbase/src/main/java/org.jhotdraw8.fxbase/org/jhotdraw8/fxbase/styleable/StyleableBean.java +++ b/org.jhotdraw8.fxbase/src/main/java/org.jhotdraw8.fxbase/org/jhotdraw8/fxbase/styleable/StyleableBean.java @@ -8,7 +8,7 @@ import javafx.beans.property.ReadOnlyProperty; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.readonly.ReadOnlySet; +import org.jhotdraw8.icollection.readonly.ReadOnlySet; /** * Styleable comprises the minimal interface required for a component (bean) diff --git a/org.jhotdraw8.fxbase/src/main/java/org.jhotdraw8.fxbase/org/jhotdraw8/fxbase/styleable/WritableStyleableMapAccessor.java b/org.jhotdraw8.fxbase/src/main/java/org.jhotdraw8.fxbase/org/jhotdraw8/fxbase/styleable/WritableStyleableMapAccessor.java index 5e003f1e2..e5fe5a839 100755 --- a/org.jhotdraw8.fxbase/src/main/java/org.jhotdraw8.fxbase/org/jhotdraw8/fxbase/styleable/WritableStyleableMapAccessor.java +++ b/org.jhotdraw8.fxbase/src/main/java/org.jhotdraw8.fxbase/org/jhotdraw8/fxbase/styleable/WritableStyleableMapAccessor.java @@ -6,8 +6,8 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.base.converter.Converter; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; /** * Interface for keys which support styled values from CSS. diff --git a/org.jhotdraw8.fxcollection/pom.xml b/org.jhotdraw8.fxcollection/pom.xml index faeb8e41b..c7ac207a2 100644 --- a/org.jhotdraw8.fxcollection/pom.xml +++ b/org.jhotdraw8.fxcollection/pom.xml @@ -52,6 +52,11 @@ org.jhotdraw8.collection ${revision} + + ch.randelshofer + org.jhotdraw8.icollection + ${revision} + com.google.guava guava-testlib diff --git a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/module-info.java b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/module-info.java index 2384c59a2..241cf97ab 100755 --- a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/module-info.java +++ b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/module-info.java @@ -11,6 +11,7 @@ requires static org.jhotdraw8.annotation; requires transitive javafx.base; requires transitive org.jhotdraw8.collection; + requires transitive org.jhotdraw8.icollection; exports org.jhotdraw8.fxcollection; exports org.jhotdraw8.fxcollection.facade; diff --git a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/AbstractObservableSet.java b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/AbstractObservableSet.java index b4d2d4a4e..90df7fd22 100755 --- a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/AbstractObservableSet.java +++ b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/AbstractObservableSet.java @@ -9,7 +9,7 @@ import javafx.collections.SetChangeListener; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.readonly.ReadOnlySet; +import org.jhotdraw8.icollection.readonly.ReadOnlySet; import java.util.AbstractSet; import java.util.Collection; diff --git a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/facade/ObservableListFacade.java b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/facade/ObservableListFacade.java index ef200ce96..dd143ec79 100755 --- a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/facade/ObservableListFacade.java +++ b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/facade/ObservableListFacade.java @@ -8,8 +8,8 @@ import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.facade.ListFacade; -import org.jhotdraw8.collection.readonly.ReadOnlyList; +import org.jhotdraw8.icollection.facade.ListFacade; +import org.jhotdraw8.icollection.readonly.ReadOnlyList; import java.util.Collection; diff --git a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/facade/ObservableSetFacade.java b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/facade/ObservableSetFacade.java index 4bad88074..120371ce6 100755 --- a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/facade/ObservableSetFacade.java +++ b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/facade/ObservableSetFacade.java @@ -8,8 +8,8 @@ import javafx.collections.ObservableSet; import javafx.collections.SetChangeListener; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.facade.SetFacade; -import org.jhotdraw8.collection.readonly.ReadOnlySet; +import org.jhotdraw8.icollection.facade.SetFacade; +import org.jhotdraw8.icollection.readonly.ReadOnlySet; /** * Wraps a {@link ReadOnlySet} in the {@link ObservableSet} interface. diff --git a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/indexedset/AbstractIndexedArrayObservableSet.java b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/indexedset/AbstractIndexedArrayObservableSet.java index 9e341c3b3..00c2f3dfe 100755 --- a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/indexedset/AbstractIndexedArrayObservableSet.java +++ b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/indexedset/AbstractIndexedArrayObservableSet.java @@ -7,13 +7,23 @@ import javafx.collections.ObservableListBase; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.facade.ReadOnlySequencedSetFacade; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedSet; -import org.jhotdraw8.collection.readonly.ReadOnlySet; import org.jhotdraw8.collection.spliterator.ReverseListSpliterator; import org.jhotdraw8.fxcollection.precondition.Preconditions; - -import java.util.*; +import org.jhotdraw8.icollection.facade.ReadOnlySequencedSetFacade; +import org.jhotdraw8.icollection.readonly.ReadOnlySequencedSet; +import org.jhotdraw8.icollection.readonly.ReadOnlySet; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.ConcurrentModificationException; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.NoSuchElementException; +import java.util.Set; +import java.util.Spliterator; +import java.util.Spliterators; import java.util.stream.Stream; import static java.lang.Math.max; @@ -811,7 +821,8 @@ public int hashCode() { this::size, this::contains, this::getLast, - this::getFirst + this::getFirst, + Spliterator.DISTINCT | Spliterator.SIZED ); } } diff --git a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/Key.java b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/Key.java index c9db340a7..1cc4f3150 100755 --- a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/Key.java +++ b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/Key.java @@ -13,8 +13,8 @@ import javafx.collections.ObservableMap; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableMap; -import org.jhotdraw8.collection.readonly.ReadOnlyMap; +import org.jhotdraw8.icollection.immutable.ImmutableMap; +import org.jhotdraw8.icollection.readonly.ReadOnlyMap; import java.lang.reflect.ParameterizedType; import java.util.Map; diff --git a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/MapAccessor.java b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/MapAccessor.java index d435fbc54..de7cff8e4 100755 --- a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/MapAccessor.java +++ b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/MapAccessor.java @@ -6,8 +6,8 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableMap; -import org.jhotdraw8.collection.readonly.ReadOnlyMap; +import org.jhotdraw8.icollection.immutable.ImmutableMap; +import org.jhotdraw8.icollection.readonly.ReadOnlyMap; import java.io.Serializable; import java.lang.reflect.ParameterizedType; diff --git a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/NonNullKey.java b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/NonNullKey.java index 8c6fea903..172f4e805 100755 --- a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/NonNullKey.java +++ b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/NonNullKey.java @@ -5,7 +5,7 @@ package org.jhotdraw8.fxcollection.typesafekey; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.readonly.ReadOnlyMap; +import org.jhotdraw8.icollection.readonly.ReadOnlyMap; import java.util.Map; diff --git a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/NonNullMapAccessor.java b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/NonNullMapAccessor.java index 12f857393..1ac7884b7 100755 --- a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/NonNullMapAccessor.java +++ b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/NonNullMapAccessor.java @@ -5,7 +5,7 @@ package org.jhotdraw8.fxcollection.typesafekey; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.readonly.ReadOnlyMap; +import org.jhotdraw8.icollection.readonly.ReadOnlyMap; import java.util.Map; import java.util.Objects; diff --git a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/NullableKey.java b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/NullableKey.java index ba9ed2d9b..a0cdd3641 100755 --- a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/NullableKey.java +++ b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/NullableKey.java @@ -6,7 +6,7 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.readonly.ReadOnlyMap; +import org.jhotdraw8.icollection.readonly.ReadOnlyMap; import java.util.Map; diff --git a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/SetValueMapAccessor.java b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/SetValueMapAccessor.java index 585b40f29..bad02275b 100755 --- a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/SetValueMapAccessor.java +++ b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/SetValueMapAccessor.java @@ -6,9 +6,9 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableMap; -import org.jhotdraw8.collection.immutable.ImmutableSet; -import org.jhotdraw8.collection.readonly.ReadOnlyMap; +import org.jhotdraw8.icollection.immutable.ImmutableMap; +import org.jhotdraw8.icollection.immutable.ImmutableSet; +import org.jhotdraw8.icollection.readonly.ReadOnlyMap; import java.io.Serial; import java.util.Collections; diff --git a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/SimpleNonNullListKey.java b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/SimpleNonNullListKey.java index 4c1613232..aa063f1a7 100755 --- a/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/SimpleNonNullListKey.java +++ b/org.jhotdraw8.fxcollection/src/main/java/org.jhotdraw8.fxcollection/org/jhotdraw8/fxcollection/typesafekey/SimpleNonNullListKey.java @@ -5,9 +5,9 @@ package org.jhotdraw8.fxcollection.typesafekey; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.reflect.TypeToken; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.io.Serial; diff --git a/org.jhotdraw8.fxcontrols/pom.xml b/org.jhotdraw8.fxcontrols/pom.xml index 4d4d2415d..e50139e24 100644 --- a/org.jhotdraw8.fxcontrols/pom.xml +++ b/org.jhotdraw8.fxcontrols/pom.xml @@ -62,5 +62,9 @@ ch.randelshofer org.jhotdraw8.geom + + ch.randelshofer + org.jhotdraw8.icollection + diff --git a/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/module-info.java b/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/module-info.java index 33d5e1a6a..6b11121a2 100755 --- a/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/module-info.java +++ b/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/module-info.java @@ -20,6 +20,7 @@ requires transitive org.jhotdraw8.fxbase; requires transitive org.jhotdraw8.color; requires transitive org.jhotdraw8.geom; + requires org.jhotdraw8.icollection; exports org.jhotdraw8.fxcontrols.dock; exports org.jhotdraw8.fxcontrols.colorchooser; exports org.jhotdraw8.fxcontrols.spi; diff --git a/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/dock/AbstractDockable.java b/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/dock/AbstractDockable.java index a340db8d1..67363f2e9 100644 --- a/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/dock/AbstractDockable.java +++ b/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/dock/AbstractDockable.java @@ -13,8 +13,8 @@ import javafx.beans.property.StringProperty; import javafx.scene.Node; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.readonly.ReadOnlyList; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.readonly.ReadOnlyList; /** * Abstract base class for implementations of {@link Dockable}. diff --git a/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/dock/DockNode.java b/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/dock/DockNode.java index 0391603f0..7157ac51a 100755 --- a/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/dock/DockNode.java +++ b/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/dock/DockNode.java @@ -8,7 +8,7 @@ import javafx.scene.Node; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.readonly.ReadOnlyList; +import org.jhotdraw8.icollection.readonly.ReadOnlyList; /** * Represents a node in a tree structure. diff --git a/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/dock/DockParent.java b/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/dock/DockParent.java index 0e7475852..0c835bdfc 100755 --- a/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/dock/DockParent.java +++ b/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/dock/DockParent.java @@ -7,8 +7,8 @@ import javafx.beans.property.BooleanProperty; import javafx.collections.ObservableList; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.facade.ReadOnlyListFacade; -import org.jhotdraw8.collection.readonly.ReadOnlyList; +import org.jhotdraw8.icollection.facade.ReadOnlyListFacade; +import org.jhotdraw8.icollection.readonly.ReadOnlyList; /** * A DockParent provides screen space for one or more {@link DockChild}ren. diff --git a/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/dock/SimpleDockable.java b/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/dock/SimpleDockable.java index 49b53fffb..e685e640e 100755 --- a/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/dock/SimpleDockable.java +++ b/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/dock/SimpleDockable.java @@ -9,8 +9,8 @@ import javafx.scene.Node; import javafx.scene.text.Text; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.readonly.ReadOnlyList; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.readonly.ReadOnlyList; public class SimpleDockable extends AbstractDockable { private final Node node; diff --git a/org.jhotdraw8.geom/pom.xml b/org.jhotdraw8.geom/pom.xml index 510a77c65..c7e9bd469 100644 --- a/org.jhotdraw8.geom/pom.xml +++ b/org.jhotdraw8.geom/pom.xml @@ -52,6 +52,10 @@ ch.randelshofer + org.jhotdraw8.icollection + + + ch.randelshofer org.jhotdraw8.base diff --git a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/module-info.java b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/module-info.java index f0cbf6055..f3ac0afe4 100755 --- a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/module-info.java +++ b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/module-info.java @@ -19,4 +19,5 @@ requires transitive org.jhotdraw8.collection; requires transitive org.jhotdraw8.base; requires java.logging; + requires org.jhotdraw8.icollection; } \ No newline at end of file diff --git a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/CutStartPathBuilder.java b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/CutStartPathBuilder.java index 08816bff5..dce8f9684 100755 --- a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/CutStartPathBuilder.java +++ b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/CutStartPathBuilder.java @@ -7,13 +7,13 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.geom.intersect.IntersectCircleCubicCurve; import org.jhotdraw8.geom.intersect.IntersectCircleLine; import org.jhotdraw8.geom.intersect.IntersectCircleQuadCurve; import org.jhotdraw8.geom.intersect.IntersectionPoint; import org.jhotdraw8.geom.intersect.IntersectionResult; import org.jhotdraw8.geom.intersect.IntersectionResultEx; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.awt.geom.Point2D; diff --git a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/contour/ContourBuilder.java b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/contour/ContourBuilder.java index 5bc560bb6..282a939d0 100755 --- a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/contour/ContourBuilder.java +++ b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/contour/ContourBuilder.java @@ -7,7 +7,6 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.base.function.QuintFunction; import org.jhotdraw8.base.function.TriConsumer; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.OrderedPair; import org.jhotdraw8.collection.pair.SimpleOrderedPair; import org.jhotdraw8.collection.primitive.IntArrayDeque; @@ -20,16 +19,42 @@ import org.jhotdraw8.geom.intersect.IntersectionPointEx; import org.jhotdraw8.geom.intersect.IntersectionResult; import org.jhotdraw8.geom.intersect.IntersectionResultEx; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.awt.geom.Point2D; -import java.util.*; -import java.util.function.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.BitSet; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.BiPredicate; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.IntPredicate; +import java.util.function.Predicate; import static org.jhotdraw8.geom.contour.BulgeConversionFunctions.arcRadiusAndCenter; -import static org.jhotdraw8.geom.contour.ContourIntersections.*; -import static org.jhotdraw8.geom.contour.PlineVertex.*; +import static org.jhotdraw8.geom.contour.ContourIntersections.allSelfIntersects; +import static org.jhotdraw8.geom.contour.ContourIntersections.findIntersects; +import static org.jhotdraw8.geom.contour.ContourIntersections.intrCircle2Circle2; +import static org.jhotdraw8.geom.contour.ContourIntersections.intrLineSeg2Circle2; +import static org.jhotdraw8.geom.contour.ContourIntersections.intrLineSeg2LineSeg2; +import static org.jhotdraw8.geom.contour.ContourIntersections.intrPlineSegs; +import static org.jhotdraw8.geom.contour.PlineVertex.closestPointOnSeg; +import static org.jhotdraw8.geom.contour.PlineVertex.createFastApproxBoundingBox; +import static org.jhotdraw8.geom.contour.PlineVertex.segMidpoint; +import static org.jhotdraw8.geom.contour.PlineVertex.splitAtPoint; import static org.jhotdraw8.geom.contour.PolyArcPath.createApproxSpatialIndex; -import static org.jhotdraw8.geom.contour.Utils.*; +import static org.jhotdraw8.geom.contour.Utils.angle; +import static org.jhotdraw8.geom.contour.Utils.deltaAngle; +import static org.jhotdraw8.geom.contour.Utils.pointFromParametric; +import static org.jhotdraw8.geom.contour.Utils.pointWithinArcSweepAngle; +import static org.jhotdraw8.geom.contour.Utils.realPrecision; +import static org.jhotdraw8.geom.contour.Utils.sliceJoinThreshold; +import static org.jhotdraw8.geom.contour.Utils.unitPerp; /** * ContourBuilder. diff --git a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/contour/ContourIntersections.java b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/contour/ContourIntersections.java index a54cc73ab..22819630d 100755 --- a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/contour/ContourIntersections.java +++ b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/contour/ContourIntersections.java @@ -8,7 +8,6 @@ import org.jhotdraw8.base.function.QuadConsumer; import org.jhotdraw8.base.function.TriConsumer; import org.jhotdraw8.base.function.TriFunction; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.NonNullOrderedPair; import org.jhotdraw8.collection.pair.OrderedPair; import org.jhotdraw8.collection.pair.SimpleOrderedPair; @@ -17,14 +16,26 @@ import org.jhotdraw8.geom.AABB; import org.jhotdraw8.geom.Points; import org.jhotdraw8.geom.Rectangles; -import org.jhotdraw8.geom.intersect.*; +import org.jhotdraw8.geom.intersect.IntersectCircleCircle; +import org.jhotdraw8.geom.intersect.IntersectCircleLine; +import org.jhotdraw8.geom.intersect.IntersectLineLine; +import org.jhotdraw8.geom.intersect.IntersectionPoint; +import org.jhotdraw8.geom.intersect.IntersectionPointEx; +import org.jhotdraw8.geom.intersect.IntersectionResult; +import org.jhotdraw8.geom.intersect.IntersectionResultEx; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.awt.geom.Point2D; import java.util.Deque; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.function.*; +import java.util.function.BiPredicate; +import java.util.function.DoubleFunction; +import java.util.function.IntConsumer; +import java.util.function.IntPredicate; +import java.util.function.Predicate; +import java.util.function.Supplier; import static org.jhotdraw8.geom.contour.BulgeConversionFunctions.arcRadiusAndCenter; import static org.jhotdraw8.geom.contour.PlineVertex.createFastApproxBoundingBox; diff --git a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/intersect/IntersectionResult.java b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/intersect/IntersectionResult.java index cfc5b00d7..96cc7ae3d 100644 --- a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/intersect/IntersectionResult.java +++ b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/intersect/IntersectionResult.java @@ -5,10 +5,10 @@ package org.jhotdraw8.geom.intersect; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableCollection; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.primitive.DoubleArrayList; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableCollection; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.Collection; diff --git a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/intersect/IntersectionResultEx.java b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/intersect/IntersectionResultEx.java index a433694a4..9dbe5ca7f 100755 --- a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/intersect/IntersectionResultEx.java +++ b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/intersect/IntersectionResultEx.java @@ -5,9 +5,9 @@ package org.jhotdraw8.geom.intersect; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.primitive.DoubleArrayList; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.Collections; import java.util.List; diff --git a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/shape/BezierNodePath.java b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/shape/BezierNodePath.java index 02260c99d..9a4ebd771 100755 --- a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/shape/BezierNodePath.java +++ b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/shape/BezierNodePath.java @@ -6,13 +6,13 @@ import javafx.scene.shape.FillRule; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.geom.CubicCurves; import org.jhotdraw8.geom.QuadCurves; import org.jhotdraw8.geom.intersect.IntersectPathIteratorPoint; import org.jhotdraw8.geom.intersect.IntersectionPoint; import org.jhotdraw8.geom.intersect.IntersectionResult; import org.jhotdraw8.geom.intersect.IntersectionStatus; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.awt.*; import java.awt.geom.AffineTransform; diff --git a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/shape/BezierNodePathBuilder.java b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/shape/BezierNodePathBuilder.java index 79c42a269..dae98ed99 100755 --- a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/shape/BezierNodePathBuilder.java +++ b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/shape/BezierNodePathBuilder.java @@ -5,9 +5,9 @@ package org.jhotdraw8.geom.shape; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.geom.AbstractPathBuilder; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.ArrayList; import java.util.List; diff --git a/org.jhotdraw8.graph/pom.xml b/org.jhotdraw8.graph/pom.xml index 0c239192f..9dad33e1c 100644 --- a/org.jhotdraw8.graph/pom.xml +++ b/org.jhotdraw8.graph/pom.xml @@ -52,6 +52,10 @@ ch.randelshofer + org.jhotdraw8.icollection + + + ch.randelshofer org.jhotdraw8.collection diff --git a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/module-info.java b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/module-info.java index f5e9c941e..d6c6780fd 100755 --- a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/module-info.java +++ b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/module-info.java @@ -11,6 +11,7 @@ requires static org.jhotdraw8.annotation; requires transitive org.jhotdraw8.base; requires transitive org.jhotdraw8.collection; + requires org.jhotdraw8.icollection; exports org.jhotdraw8.graph; exports org.jhotdraw8.graph.algo; diff --git a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/BidiGraph.java b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/BidiGraph.java index dd42fcfff..f0d5e9890 100755 --- a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/BidiGraph.java +++ b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/BidiGraph.java @@ -6,9 +6,9 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.collection.enumerator.Enumerator; -import org.jhotdraw8.collection.facade.ListFacade; import org.jhotdraw8.graph.algo.AddToSet; import org.jhotdraw8.graph.iterator.BfsDfsVertexSpliterator; +import org.jhotdraw8.icollection.facade.ListFacade; import java.util.Collection; import java.util.HashSet; diff --git a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/DirectedGraph.java b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/DirectedGraph.java index e87d8f9cf..52ca8f780 100755 --- a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/DirectedGraph.java +++ b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/DirectedGraph.java @@ -7,9 +7,9 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.collection.enumerator.Enumerator; -import org.jhotdraw8.collection.facade.ListFacade; import org.jhotdraw8.graph.algo.AddToSet; import org.jhotdraw8.graph.iterator.BfsDfsVertexSpliterator; +import org.jhotdraw8.icollection.facade.ListFacade; import java.util.ArrayList; import java.util.Collection; diff --git a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/SimpleMutableDirectedGraph.java b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/SimpleMutableDirectedGraph.java index 686d09b65..7c90baf08 100755 --- a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/SimpleMutableDirectedGraph.java +++ b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/SimpleMutableDirectedGraph.java @@ -8,7 +8,7 @@ import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.function.TriFunction; import org.jhotdraw8.collection.enumerator.Enumerator; -import org.jhotdraw8.collection.facade.SetFacade; +import org.jhotdraw8.icollection.facade.SetFacade; import java.util.ArrayList; import java.util.HashMap; diff --git a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/AllArcSequencesFinder.java b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/AllArcSequencesFinder.java index f019a4420..499e62fc8 100644 --- a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/AllArcSequencesFinder.java +++ b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/AllArcSequencesFinder.java @@ -6,9 +6,9 @@ package org.jhotdraw8.graph.path; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.OrderedPair; import org.jhotdraw8.graph.Arc; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.function.Predicate; diff --git a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/AllArrowsSequencesFinder.java b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/AllArrowsSequencesFinder.java index 1ed955bc7..2eab2e041 100644 --- a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/AllArrowsSequencesFinder.java +++ b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/AllArrowsSequencesFinder.java @@ -6,8 +6,8 @@ package org.jhotdraw8.graph.path; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.OrderedPair; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.function.Predicate; diff --git a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/AllVertexSequencesFinder.java b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/AllVertexSequencesFinder.java index 0fc3ea6df..900211dd4 100644 --- a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/AllVertexSequencesFinder.java +++ b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/AllVertexSequencesFinder.java @@ -6,8 +6,8 @@ package org.jhotdraw8.graph.path; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.OrderedPair; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.function.Predicate; diff --git a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/ArcSequenceFinder.java b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/ArcSequenceFinder.java index 190d0e336..037bd75dd 100644 --- a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/ArcSequenceFinder.java +++ b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/ArcSequenceFinder.java @@ -7,12 +7,12 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.OrderedPair; import org.jhotdraw8.collection.pair.SimpleOrderedPair; import org.jhotdraw8.graph.Arc; import org.jhotdraw8.graph.algo.AddToSet; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.ArrayList; import java.util.HashSet; diff --git a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/ArrowSequenceFinder.java b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/ArrowSequenceFinder.java index 4be420e2d..ecba15216 100644 --- a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/ArrowSequenceFinder.java +++ b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/ArrowSequenceFinder.java @@ -7,11 +7,11 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.OrderedPair; import org.jhotdraw8.collection.pair.SimpleOrderedPair; import org.jhotdraw8.graph.algo.AddToSet; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.ArrayList; import java.util.HashSet; diff --git a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/SimpleCombinedAllSequencesFinder.java b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/SimpleCombinedAllSequencesFinder.java index c68c49830..e76f9e40e 100644 --- a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/SimpleCombinedAllSequencesFinder.java +++ b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/SimpleCombinedAllSequencesFinder.java @@ -7,12 +7,12 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.base.function.TriFunction; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.OrderedPair; import org.jhotdraw8.collection.spliterator.SpliteratorIterable; import org.jhotdraw8.graph.Arc; import org.jhotdraw8.graph.path.algo.AllWalksSpliterator; import org.jhotdraw8.graph.path.backlink.ArcBackLinkWithCost; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.function.BiFunction; import java.util.function.Function; diff --git a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/SimpleCombinedSequenceFinder.java b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/SimpleCombinedSequenceFinder.java index 20ac05de0..cd2b69191 100644 --- a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/SimpleCombinedSequenceFinder.java +++ b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/SimpleCombinedSequenceFinder.java @@ -8,13 +8,13 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.function.TriFunction; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.OrderedPair; import org.jhotdraw8.collection.pair.SimpleOrderedPair; import org.jhotdraw8.graph.Arc; import org.jhotdraw8.graph.algo.AddToSet; import org.jhotdraw8.graph.path.algo.ArcPathSearchAlgo; import org.jhotdraw8.graph.path.backlink.ArcBackLinkWithCost; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.function.BiFunction; import java.util.function.Function; diff --git a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/SimpleIndexedVertexSequenceFinder.java b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/SimpleIndexedVertexSequenceFinder.java index 67e97681f..4252dcb99 100644 --- a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/SimpleIndexedVertexSequenceFinder.java +++ b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/SimpleIndexedVertexSequenceFinder.java @@ -7,12 +7,12 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.SimpleOrderedPair; import org.jhotdraw8.graph.algo.AddToIntSet; import org.jhotdraw8.graph.algo.AddToSet; import org.jhotdraw8.graph.path.algo.IndexedVertexPathSearchAlgo; import org.jhotdraw8.graph.path.backlink.IndexedVertexBackLinkWithCost; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.Spliterator; import java.util.function.BiFunction; diff --git a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/SimpleVertexSequenceFinder.java b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/SimpleVertexSequenceFinder.java index 1d61e5496..7bed079c3 100644 --- a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/SimpleVertexSequenceFinder.java +++ b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/SimpleVertexSequenceFinder.java @@ -7,11 +7,11 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.SimpleOrderedPair; import org.jhotdraw8.graph.algo.AddToSet; import org.jhotdraw8.graph.path.algo.VertexPathSearchAlgo; import org.jhotdraw8.graph.path.backlink.VertexBackLinkWithCost; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.function.BiFunction; import java.util.function.Function; diff --git a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/VertexSequenceFinder.java b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/VertexSequenceFinder.java index 5385d0f8a..5d07bb675 100644 --- a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/VertexSequenceFinder.java +++ b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/VertexSequenceFinder.java @@ -7,11 +7,11 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.OrderedPair; import org.jhotdraw8.collection.pair.SimpleOrderedPair; import org.jhotdraw8.graph.algo.AddToSet; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.ArrayList; import java.util.Collections; diff --git a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/AllWalksSpliterator.java b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/AllWalksSpliterator.java index b8442f381..766713f64 100644 --- a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/AllWalksSpliterator.java +++ b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/AllWalksSpliterator.java @@ -8,10 +8,10 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.base.function.TriFunction; import org.jhotdraw8.collection.enumerator.AbstractEnumerator; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.OrderedPair; import org.jhotdraw8.graph.Arc; import org.jhotdraw8.graph.path.backlink.ArcBackLinkWithCost; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.ArrayDeque; import java.util.Queue; diff --git a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/UniqueOnDigArcPathSearchAlgo.java b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/UniqueOnDigArcPathSearchAlgo.java index 1769d101d..ab2d02055 100755 --- a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/UniqueOnDigArcPathSearchAlgo.java +++ b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/UniqueOnDigArcPathSearchAlgo.java @@ -7,14 +7,18 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.function.TriFunction; -import org.jhotdraw8.collection.AddOnlyChampSet; import org.jhotdraw8.collection.pair.SimpleOrderedPair; import org.jhotdraw8.graph.Arc; import org.jhotdraw8.graph.algo.AddToSet; import org.jhotdraw8.graph.path.backlink.ArcBackLinkWithAncestorSet; import org.jhotdraw8.graph.path.backlink.ArcBackLinkWithCost; +import org.jhotdraw8.icollection.AddOnlyChampSet; -import java.util.*; +import java.util.ArrayDeque; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Queue; import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Predicate; diff --git a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/UniqueOnDigVertexPathSearchAlgo.java b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/UniqueOnDigVertexPathSearchAlgo.java index 6907b3eee..71ab7371d 100755 --- a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/UniqueOnDigVertexPathSearchAlgo.java +++ b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/UniqueOnDigVertexPathSearchAlgo.java @@ -6,11 +6,11 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.AddOnlyChampSet; import org.jhotdraw8.collection.pair.SimpleOrderedPair; import org.jhotdraw8.graph.algo.AddToSet; import org.jhotdraw8.graph.path.backlink.VertexBackLinkWithAncestorSet; import org.jhotdraw8.graph.path.backlink.VertexBackLinkWithCost; +import org.jhotdraw8.icollection.AddOnlyChampSet; import java.util.ArrayDeque; import java.util.LinkedHashMap; diff --git a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/backlink/ArcBackLinkWithAncestorSet.java b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/backlink/ArcBackLinkWithAncestorSet.java index c8040c792..2908e7143 100644 --- a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/backlink/ArcBackLinkWithAncestorSet.java +++ b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/backlink/ArcBackLinkWithAncestorSet.java @@ -8,7 +8,7 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.function.TriFunction; -import org.jhotdraw8.collection.AddOnlyChampSet; +import org.jhotdraw8.icollection.AddOnlyChampSet; import java.util.ArrayDeque; import java.util.Deque; diff --git a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/backlink/ArcBackLinkWithCost.java b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/backlink/ArcBackLinkWithCost.java index bebfc0302..22973297a 100644 --- a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/backlink/ArcBackLinkWithCost.java +++ b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/backlink/ArcBackLinkWithCost.java @@ -7,9 +7,9 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.SimpleOrderedPair; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.ArrayDeque; import java.util.Deque; diff --git a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/backlink/IndexedVertexBackLinkWithCost.java b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/backlink/IndexedVertexBackLinkWithCost.java index 58523eb2d..149bf176c 100644 --- a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/backlink/IndexedVertexBackLinkWithCost.java +++ b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/backlink/IndexedVertexBackLinkWithCost.java @@ -7,9 +7,9 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.SimpleOrderedPair; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.ArrayDeque; import java.util.Deque; diff --git a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/backlink/VertexBackLinkWithAncestorSet.java b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/backlink/VertexBackLinkWithAncestorSet.java index 9b669be66..560fa266b 100644 --- a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/backlink/VertexBackLinkWithAncestorSet.java +++ b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/backlink/VertexBackLinkWithAncestorSet.java @@ -7,7 +7,7 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.AddOnlyChampSet; +import org.jhotdraw8.icollection.AddOnlyChampSet; import java.util.ArrayDeque; import java.util.Deque; diff --git a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/backlink/VertexBackLinkWithCost.java b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/backlink/VertexBackLinkWithCost.java index b55a7a5e5..9e376f75a 100644 --- a/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/backlink/VertexBackLinkWithCost.java +++ b/org.jhotdraw8.graph/src/main/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/backlink/VertexBackLinkWithCost.java @@ -7,9 +7,9 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.SimpleOrderedPair; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.ArrayDeque; import java.util.function.Function; diff --git a/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/BfsDfsArcSpliteratorTest.java b/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/BfsDfsArcSpliteratorTest.java index c2058d0ad..056aa1f21 100755 --- a/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/BfsDfsArcSpliteratorTest.java +++ b/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/BfsDfsArcSpliteratorTest.java @@ -6,13 +6,17 @@ package org.jhotdraw8.graph; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.graph.iterator.BfsDfsArcSpliterator; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.TestFactory; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.DynamicTest.dynamicTest; diff --git a/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/UniqueOrOneHopVertexPathSearchAlgoTest.java b/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/UniqueOrOneHopVertexPathSearchAlgoTest.java index 137678383..4424220e1 100755 --- a/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/UniqueOrOneHopVertexPathSearchAlgoTest.java +++ b/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/UniqueOrOneHopVertexPathSearchAlgoTest.java @@ -6,13 +6,13 @@ package org.jhotdraw8.graph; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.SimpleOrderedPair; import org.jhotdraw8.graph.io.AdjacencyListWriter; import org.jhotdraw8.graph.path.SimpleVertexSequenceFinder; import org.jhotdraw8.graph.path.VertexSequenceFinder; import org.jhotdraw8.graph.path.algo.UniqueOrOneHopVertexPathSearchAlgo; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestFactory; @@ -20,7 +20,9 @@ import java.util.Arrays; import java.util.List; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.DynamicTest.dynamicTest; /** diff --git a/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/AllWalksSpliteratorTest.java b/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/AllWalksSpliteratorTest.java index abb752b76..6ab7f1afe 100755 --- a/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/AllWalksSpliteratorTest.java +++ b/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/AllWalksSpliteratorTest.java @@ -5,13 +5,13 @@ package org.jhotdraw8.graph.path.algo; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.OrderedPair; import org.jhotdraw8.graph.DirectedGraph; import org.jhotdraw8.graph.SimpleMutableDirectedGraph; import org.jhotdraw8.graph.path.CombinedAllSequencesFinder; import org.jhotdraw8.graph.path.SimpleCombinedAllSequencesFinder; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.TestFactory; diff --git a/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/ArbitraryArcPathSearchAlgoTest.java b/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/ArbitraryArcPathSearchAlgoTest.java index a235c8596..0ef627f98 100755 --- a/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/ArbitraryArcPathSearchAlgoTest.java +++ b/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/ArbitraryArcPathSearchAlgoTest.java @@ -7,8 +7,6 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.function.ToIntTriFunction; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.SimpleOrderedPair; import org.jhotdraw8.graph.DirectedGraph; import org.jhotdraw8.graph.SimpleMutableDirectedGraph; @@ -17,6 +15,8 @@ import org.jhotdraw8.graph.path.CombinedSequenceFinder; import org.jhotdraw8.graph.path.SimpleCombinedAllSequencesFinder; import org.jhotdraw8.graph.path.SimpleCombinedSequenceFinder; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestFactory; diff --git a/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/ArbitraryShortestArcPathSearchAlgoTest.java b/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/ArbitraryShortestArcPathSearchAlgoTest.java index 156956800..edd4124b2 100755 --- a/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/ArbitraryShortestArcPathSearchAlgoTest.java +++ b/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/ArbitraryShortestArcPathSearchAlgoTest.java @@ -7,14 +7,14 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.base.function.TriFunction; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.SimpleOrderedPair; import org.jhotdraw8.graph.DirectedGraph; import org.jhotdraw8.graph.SimpleMutableDirectedGraph; import org.jhotdraw8.graph.io.AdjacencyListWriter; import org.jhotdraw8.graph.path.CombinedSequenceFinder; import org.jhotdraw8.graph.path.SimpleCombinedSequenceFinder; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestFactory; @@ -23,7 +23,9 @@ import java.util.List; import java.util.function.ToDoubleFunction; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.DynamicTest.dynamicTest; /** diff --git a/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/UniqueOnDagVertexPathSearchAlgoTest.java b/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/UniqueOnDagVertexPathSearchAlgoTest.java index f8b17ff17..834269412 100755 --- a/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/UniqueOnDagVertexPathSearchAlgoTest.java +++ b/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/UniqueOnDagVertexPathSearchAlgoTest.java @@ -7,13 +7,13 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.SimpleOrderedPair; import org.jhotdraw8.graph.DirectedGraph; import org.jhotdraw8.graph.SimpleMutableDirectedGraph; import org.jhotdraw8.graph.io.AdjacencyListWriter; import org.jhotdraw8.graph.path.SimpleVertexSequenceFinder; import org.jhotdraw8.graph.path.VertexSequenceFinder; +import org.jhotdraw8.icollection.immutable.ImmutableList; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestFactory; @@ -21,7 +21,9 @@ import java.util.Arrays; import java.util.List; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.DynamicTest.dynamicTest; /** diff --git a/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/UniqueShortestArcPathSearchAlgoTest.java b/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/UniqueShortestArcPathSearchAlgoTest.java index b37297d3d..d11962a42 100755 --- a/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/UniqueShortestArcPathSearchAlgoTest.java +++ b/org.jhotdraw8.graph/src/test/java/org.jhotdraw8.graph/org/jhotdraw8/graph/path/algo/UniqueShortestArcPathSearchAlgoTest.java @@ -7,14 +7,14 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.base.function.TriFunction; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.pair.SimpleOrderedPair; import org.jhotdraw8.graph.DirectedGraph; import org.jhotdraw8.graph.SimpleMutableDirectedGraph; import org.jhotdraw8.graph.io.AdjacencyListWriter; import org.jhotdraw8.graph.path.CombinedSequenceFinder; import org.jhotdraw8.graph.path.SimpleCombinedSequenceFinder; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestFactory; diff --git a/org.jhotdraw8.grapher/src/main/java/org.jhotdraw8.grapher/org/jhotdraw8/grapher/GrapherActivity.java b/org.jhotdraw8.grapher/src/main/java/org.jhotdraw8.grapher/org/jhotdraw8/grapher/GrapherActivity.java index 994f1f14a..de0959068 100755 --- a/org.jhotdraw8.grapher/src/main/java/org.jhotdraw8.grapher/org/jhotdraw8/grapher/GrapherActivity.java +++ b/org.jhotdraw8.grapher/src/main/java/org.jhotdraw8.grapher/org/jhotdraw8/grapher/GrapherActivity.java @@ -29,8 +29,6 @@ import org.jhotdraw8.application.action.view.ToggleBooleanAction; import org.jhotdraw8.application.resources.Resources; import org.jhotdraw8.base.converter.IdFactory; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.draw.DrawingEditor; import org.jhotdraw8.draw.DrawingEditorPreferencesHandler; import org.jhotdraw8.draw.DrawingView; @@ -133,6 +131,8 @@ import org.jhotdraw8.fxcontrols.dock.TabbedAccordionTrack; import org.jhotdraw8.fxcontrols.dock.Track; import org.jhotdraw8.fxcontrols.dock.VBoxTrack; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import org.jhotdraw8.svg.gui.SvgDrawingExportOptionsPane; import org.jhotdraw8.svg.io.FXSvgFullWriter; import org.jhotdraw8.svg.io.FXSvgTinyWriter; diff --git a/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/module-info.java b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/module-info.java index 53339c484..74ac44864 100755 --- a/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/module-info.java +++ b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/module-info.java @@ -10,6 +10,8 @@ @SuppressWarnings("module") module org.jhotdraw8.icollection { requires static org.jhotdraw8.annotation; + exports org.jhotdraw8.icollection.exception; + exports org.jhotdraw8.icollection.facade; exports org.jhotdraw8.icollection.immutable; exports org.jhotdraw8.icollection.readonly; exports org.jhotdraw8.icollection.sequenced; diff --git a/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ImmutableLists.java b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ImmutableLists.java new file mode 100644 index 000000000..1b9577bb3 --- /dev/null +++ b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ImmutableLists.java @@ -0,0 +1,50 @@ +package org.jhotdraw8.icollection; + +import org.jhotdraw8.icollection.immutable.ImmutableList; + +/** + * Provides factory methods for immutable lists. + */ +public class ImmutableLists { + /** + * Don't let anyone instantiate this class. + */ + private ImmutableLists() { + } + + /** + * Returns an empty immutable list. + * + * @param the element type + * @return empty immutable list + */ + public static ImmutableList of() { + return VectorList.of(); + } + + /** + * Returns a new immutable list with the specified elements. + * + * @param elements the specified elements + * @param the element type + * @return immutable list of the specified elements + */ + @SafeVarargs + public static ImmutableList of(E... elements) { + return VectorList.of(elements); + } + + /** + * Returns an immutable list with the specified elements. + *

+ * If the provided list can be cast to {@link ImmutableList} it will be cast, + * otherwise a new list will be created. + * + * @param elements the specified elements + * @param the element type + * @return immutable list of the specified elements + */ + public static ImmutableList copyOf(Iterable elements) { + return elements instanceof ImmutableList ? (ImmutableList) elements : VectorList.of().addAll(elements); + } +} diff --git a/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ImmutableMaps.java b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ImmutableMaps.java new file mode 100644 index 000000000..44a8c2014 --- /dev/null +++ b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ImmutableMaps.java @@ -0,0 +1,56 @@ +package org.jhotdraw8.icollection; + + +import org.jhotdraw8.icollection.immutable.ImmutableMap; + +import java.util.Map; + +/** + * Provides factory methods for immutable lists. + */ +public class ImmutableMaps { + /** + * Don't let anyone instantiate this class. + */ + private ImmutableMaps() { + } + + /** + * Returns an empty immutable map. + * + * @param the key type + * @param the value type + * @return empty map + */ + public static ImmutableMap of() { + return ChampMap.of(); + } + + /** + * Returns a new immutable map with the specified entries. + *

+ * If the provided iterable can be cast to {@link ImmutableMap}, + * it will be cast, otherwise a new map will be created. + * + * @param entries the specified entries + * @param the key type + * @param the value type + * @return immutable map of the specified entries + */ + @SuppressWarnings("unchecked") + public static ImmutableMap of(Iterable> entries) { + return (entries instanceof ImmutableMap) ? (ImmutableMap) entries : ChampMap.of().putAll(entries); + } + + /** + * Returns an immutable map with the specified entries. + * + * @param entries the specified entries + * @param the key type + * @param the value type + * @return immutable map of the specified entries + */ + public static ImmutableMap copyOf(Map entries) { + return ChampMap.of().putAll(entries); + } +} diff --git a/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ImmutableSequencedMaps.java b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ImmutableSequencedMaps.java new file mode 100644 index 000000000..6245d7b99 --- /dev/null +++ b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ImmutableSequencedMaps.java @@ -0,0 +1,59 @@ +package org.jhotdraw8.icollection; + + +import org.jhotdraw8.icollection.immutable.ImmutableMap; +import org.jhotdraw8.icollection.immutable.ImmutableSequencedMap; + +import java.util.Map; + +/** + * Provides factory methods for immutable sequenced maps. + */ +public class ImmutableSequencedMaps { + /** + * Don't let anyone instantiate this class. + */ + private ImmutableSequencedMaps() { + } + + /** + * Returns an empty immutable sequenced map. + * + * @param the key type + * @param the value type + * @return empty map + */ + public static ImmutableSequencedMap of() { + return VectorMap.of(); + } + + /** + * Returns an immutable sequenced map with the specified entries. + *

+ * If the provided iterable can be cast to {@link ImmutableMap}, + * it will be cast, otherwise a new map will be created. + * + * @param entries the specified entries + * @param the key type + * @param the value type + * @return immutable sequenced map of the specified entries + */ + @SuppressWarnings("unchecked") + public static ImmutableSequencedMap of(Iterable> entries) { + return (entries instanceof ImmutableSequencedMap) + ? (ImmutableSequencedMap) entries + : VectorMap.of().putAll(entries); + } + + /** + * Returns an immutable sequenced map with the specified entries. + * + * @param entries the specified entries + * @param the key type + * @param the value type + * @return immutable sequenced map of the specified entries + */ + public static ImmutableSequencedMap copyOf(Map entries) { + return VectorMap.of().putAll(entries); + } +} diff --git a/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ImmutableSequencedSets.java b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ImmutableSequencedSets.java new file mode 100644 index 000000000..222be8ffd --- /dev/null +++ b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ImmutableSequencedSets.java @@ -0,0 +1,54 @@ +package org.jhotdraw8.icollection; + + +import org.jhotdraw8.icollection.immutable.ImmutableSequencedSet; + +/** + * Provides factory methods for immutable sequenced sets. + */ +public class ImmutableSequencedSets { + /** + * Don't let anyone instantiate this class. + */ + private ImmutableSequencedSets() { + } + + /** + * Returns an empty immutable sequenced set. + * + * @param the element type + * @return empty set + */ + public static ImmutableSequencedSet of() { + return VectorSet.of(); + } + + /** + * Returns a immutable sequenced set with the specified elements. + * + * @param elements the specified elements + * @param the element type + * @return immutable sequenced set of the specified elements + */ + @SafeVarargs + public static ImmutableSequencedSet of(E... elements) { + return VectorSet.of(elements); + } + + /** + * Returns an immutable sequenced set with the specified elements. + *

+ * If the provided iterable can be cast to {@link ImmutableSequencedSet} it will be cast, + * otherwise a new set will be created. + * + * @param elements the specified elements + * @param the element type + * @return immutable sequenced set of the specified elements + */ + public static ImmutableSequencedSet copyOf(Iterable elements) { + return elements instanceof ImmutableSequencedSet + ? (ImmutableSequencedSet) elements : + VectorSet.of().addAll(elements); + } + +} diff --git a/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ImmutableSets.java b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ImmutableSets.java new file mode 100644 index 000000000..f81f7acc6 --- /dev/null +++ b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ImmutableSets.java @@ -0,0 +1,52 @@ +package org.jhotdraw8.icollection; + + +import org.jhotdraw8.icollection.immutable.ImmutableSet; + +/** + * Provides factory methods for immutable sets. + */ +public class ImmutableSets { + /** + * Don't let anyone instantiate this class. + */ + private ImmutableSets() { + } + + /** + * Returns an empty immutable set. + * + * @param the element type + * @return empty set + */ + public static ImmutableSet of() { + return ChampSet.of(); + } + + /** + * Returns a new immutable set with the specified elements. + * + * @param elements the specified elements + * @param the element type + * @return immutable set of the specified elements + */ + @SafeVarargs + public static ImmutableSet of(E... elements) { + return ChampSet.of(elements); + } + + /** + * Returns an immutable set with the specified elements. + *

+ * If the provided set can be cast to {@link ImmutableSet} it will be cast, + * otherwise a new set will be created. + * + * @param elements the specified elements + * @param the element type + * @return immutable set of the specified elements + */ + public static ImmutableSet copyOf(Iterable elements) { + return elements instanceof ImmutableSet ? (ImmutableSet) elements : ChampSet.of().addAll(elements); + } + +} diff --git a/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ReadOnlyLists.java b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ReadOnlyLists.java new file mode 100644 index 000000000..4ca6b4813 --- /dev/null +++ b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ReadOnlyLists.java @@ -0,0 +1,79 @@ +package org.jhotdraw8.icollection; + +import org.jhotdraw8.icollection.facade.ReadOnlyListFacade; +import org.jhotdraw8.icollection.immutable.ImmutableList; +import org.jhotdraw8.icollection.readonly.ReadOnlyList; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +/** + * Provides factory methods for read-only lists. + */ +public class ReadOnlyLists { + /** + * Don't let anyone instantiate this class. + */ + private ReadOnlyLists() { + } + + /** + * Returns an empty read-only list. + * + * @param the element type + * @return empty read-only list + */ + public static ReadOnlyList of() { + return VectorList.of(); + } + + /** + * Returns a new read-only list with the specified elements. + * + * @param elements the specified elements + * @param the element type + * @return read-only list with the specified elements + */ + @SafeVarargs + public static ReadOnlyList of(E... elements) { + return new ReadOnlyListFacade<>(Arrays.asList(elements)); + } + + /** + * Returns a read-only list with the specified elements. + *

+ * If the list can be cast to {@link org.jhotdraw8.icollection.immutable.ImmutableList}, + * it will be cast, otherwise a new list will be created. + * + * @param elements the specified elements + * @param the element type + * @return read-only list with the specified elements + */ + @SuppressWarnings("unchecked") + public static ReadOnlyList copyOf(Iterable elements) { + if (elements instanceof ImmutableList) return (ReadOnlyList) elements; + if (elements instanceof Collection) + return new ReadOnlyListFacade<>(new ArrayList<>((Collection) elements)); + ArrayList l = new ArrayList<>(); + for (var e : elements) { + l.add(e); + } + return new ReadOnlyListFacade<>(l); + } + + /** + * Returns the same list wrapped or cast into a read-only list interface. + *

+ * If the list can be cast to a {@link ReadOnlyList}, it will be cast. + * + * @param elements the specified elements + * @param the element type + * @return read-only list with the specified elements + */ + @SuppressWarnings("unchecked") + public static ReadOnlyList asReadOnly(List elements) { + return elements instanceof ReadOnlyList ? (ReadOnlyList) elements : new ReadOnlyListFacade<>(elements); + } +} diff --git a/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ReadOnlyMaps.java b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ReadOnlyMaps.java new file mode 100644 index 000000000..6e077992f --- /dev/null +++ b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ReadOnlyMaps.java @@ -0,0 +1,83 @@ +package org.jhotdraw8.icollection; + +import org.jhotdraw8.icollection.facade.ReadOnlyMapFacade; +import org.jhotdraw8.icollection.immutable.ImmutableMap; +import org.jhotdraw8.icollection.readonly.ReadOnlyMap; + +import java.util.HashMap; +import java.util.Map; + +/** + * Provides factory methods for read-only maps. + */ +public class ReadOnlyMaps { + /** + * Don't let anyone instantiate this class. + */ + private ReadOnlyMaps() { + } + + /** + * Returns an empty read-only map. + * + * @param the key type + * @param the value type + * @return empty read-only map + */ + public static ReadOnlyMap of() { + return ChampMap.of(); + } + + /** + * Returns a new read-only map with the specified entries. + *

+ * If the provided iterable can be cast to {@link ImmutableMap}, + * it will be cast, otherwise a new map will be created. + * + * @param entries the specified entries + * @param the key type + * @param the value type + * @return read-only map with the specified entries + */ + @SuppressWarnings("unchecked") + public static ReadOnlyMap of(Iterable> entries) { + if (entries instanceof ImmutableMap) return (ImmutableMap) entries; + HashMap m = new HashMap<>(); + for (var e : entries) { + m.put(e.getKey(), e.getValue()); + } + return new ReadOnlyMapFacade<>(m); + } + + /** + * Returns a read-only map with the specified entries. + *

+ * If the map can be cast to {@link org.jhotdraw8.icollection.immutable.ImmutableMap}, + * it will be cast, otherwise a new map will be created. + * + * @param entries the specified entries + * @param the key type + * @param the value type + * @return read-only map with the specified entries + */ + public static ReadOnlyMap copyOf(Map entries) { + if (entries instanceof ImmutableMap) return (ReadOnlyMap) entries; + HashMap m = new HashMap<>(entries); + return new ReadOnlyMapFacade<>(m); + } + + /** + * Returns the same map wrapped or cast into a read-only map interface. + *

+ * If the map can be cast to a {@link ReadOnlyMap}, it will be cast. + * + * @param entries the specified entries + * @param the key type + * @param the value type + * @return read-only map with the specified entries + */ + @SuppressWarnings("unchecked") + public static ReadOnlyMap asReadOnly(Map entries) { + return entries instanceof ReadOnlyMap ? (ReadOnlyMap) entries : new ReadOnlyMapFacade<>(entries); + } +} diff --git a/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ReadOnlySequencedMaps.java b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ReadOnlySequencedMaps.java new file mode 100644 index 000000000..bbfc8a470 --- /dev/null +++ b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ReadOnlySequencedMaps.java @@ -0,0 +1,85 @@ +package org.jhotdraw8.icollection; + + +import org.jhotdraw8.icollection.facade.ReadOnlySequencedMapFacade; +import org.jhotdraw8.icollection.immutable.ImmutableSequencedMap; +import org.jhotdraw8.icollection.readonly.ReadOnlySequencedMap; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.SequencedMap; + +/** + * Provides factory methods for read-only sequenced maps. + */ +public class ReadOnlySequencedMaps { + /** + * Don't let anyone instantiate this class. + */ + private ReadOnlySequencedMaps() { + } + + /** + * Returns an empty read-only sequenced map. + * + * @param the key type + * @param the value type + * @return empty read-only sequenced map + */ + public static ReadOnlySequencedMap of() { + return VectorMap.of(); + } + + /** + * Returns a new read-only sequenced map with the specified entries. + *

+ * If the provided iterable can be cast to {@link ImmutableSequencedMap}, + * it will be cast, otherwise a new map will be created. + * + * @param entries the specified entries + * @param the key type + * @param the value type + * @return read-only sequenced map with the specified entries + */ + @SuppressWarnings("unchecked") + public static ReadOnlySequencedMap of(Iterable> entries) { + if (entries instanceof ImmutableSequencedMap) return (ImmutableSequencedMap) entries; + LinkedHashMap m = new LinkedHashMap<>(); + for (var e : entries) { + m.put(e.getKey(), e.getValue()); + } + return new ReadOnlySequencedMapFacade<>(m); + } + + /** + * Returns a read-only sequenced map with the specified entries. + *

+ * If the map can be cast to {@link ImmutableSequencedMap}, + * it will be cast, otherwise a new map will be created. + * + * @param entries the specified entries + * @param the key type + * @param the value type + * @return read-only sequenced map with the specified entries + */ + public static ReadOnlySequencedMap copyOf(Map entries) { + if (entries instanceof ImmutableSequencedMap) return (ReadOnlySequencedMap) entries; + LinkedHashMap m = new LinkedHashMap<>(entries); + return new ReadOnlySequencedMapFacade<>(m); + } + + /** + * Returns the same map wrapped or cast into a read-only sequenced map interface. + *

+ * If the map can be cast to a {@link ReadOnlySequencedMap}, it will be cast. + * + * @param entries the specified entries + * @param the key type + * @param the value type + * @return a list + */ + @SuppressWarnings("unchecked") + public static ReadOnlySequencedMap asReadOnly(SequencedMap entries) { + return entries instanceof ReadOnlySequencedMap ? (ReadOnlySequencedMap) entries : new ReadOnlySequencedMapFacade<>(entries); + } +} diff --git a/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ReadOnlySequencedSets.java b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ReadOnlySequencedSets.java new file mode 100644 index 000000000..e9d566e07 --- /dev/null +++ b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ReadOnlySequencedSets.java @@ -0,0 +1,78 @@ +package org.jhotdraw8.icollection; + +import org.jhotdraw8.icollection.facade.ReadOnlySequencedSetFacade; +import org.jhotdraw8.icollection.immutable.ImmutableSequencedSet; +import org.jhotdraw8.icollection.readonly.ReadOnlySequencedSet; + +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.SequencedSet; + +/** + * Provides factory methods for read-only sequenced sets. + */ +public class ReadOnlySequencedSets { + /** + * Don't let anyone instantiate this class. + */ + private ReadOnlySequencedSets() { + } + + /** + * Returns an empty read-only sequenced set. + * + * @param the element type + * @return empty read-only sequenced set + */ + public static ReadOnlySequencedSet of() { + return VectorSet.of(); + } + + /** + * Returns a read-only sequenced set with the specified elements. + * + * @param elements the specified elements + * @param the element type + * @return read-only sequenced set with the specified elements + */ + @SafeVarargs + public static ReadOnlySequencedSet of(E... elements) { + return new ReadOnlySequencedSetFacade<>(new LinkedHashSet<>(Arrays.asList(elements))); + } + + /** + * Returns a new read-only sequenced set with the specified elements. + *

+ * If the set can be cast to {@link ImmutableSequencedSet, + * it will be cast, otherwise a new set will be created. + * + * @param elements the specified elements + * @param the element type + * @return read-only sequenced set with the specified elements + */ + public static ReadOnlySequencedSet copyOf(Iterable elements) { + if (elements instanceof ImmutableSequencedSet) return (ReadOnlySequencedSet) elements; + if (elements instanceof Collection) + return new ReadOnlySequencedSetFacade<>(new LinkedHashSet<>((Collection) elements)); + var s = new LinkedHashSet(); + for (var e : elements) { + s.add(e); + } + return new ReadOnlySequencedSetFacade<>(s); + + } + + /** + * Returns the same set wrapped or cast into a read-only sequenced set interface. + *

+ * If the set can be cast to a {@link ReadOnlySequencedSet}, it will be cast. + * + * @param elements the specified elements + * @param the element type + * @return read-only sequenced set with the specified elements + */ + public static ReadOnlySequencedSet asReadOnly(SequencedSet elements) { + return elements instanceof ReadOnlySequencedSet ? (ReadOnlySequencedSet) elements : new ReadOnlySequencedSetFacade<>(elements); + } +} diff --git a/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ReadOnlySets.java b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ReadOnlySets.java new file mode 100644 index 000000000..119cb93c6 --- /dev/null +++ b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/ReadOnlySets.java @@ -0,0 +1,76 @@ +package org.jhotdraw8.icollection; + +import org.jhotdraw8.icollection.facade.ReadOnlySetFacade; +import org.jhotdraw8.icollection.immutable.ImmutableSet; +import org.jhotdraw8.icollection.readonly.ReadOnlySet; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +/** + * Provides factory methods for immutable lists. + */ +public class ReadOnlySets { + /** + * Don't let anyone instantiate this class. + */ + private ReadOnlySets() { + } + + /** + * Returns an empty read-only set. + * + * @param the element type + * @return empty read-only set + */ + public static ReadOnlySet of() { + return ChampSet.of(); + } + + /** + * Returns a read-only set with the specified elements. + * + * @param elements the specified elements + * @param the element type + * @return read-only set with the specified elements + */ + @SafeVarargs + public static ReadOnlySet of(E... elements) { + return new ReadOnlySetFacade<>(new HashSet<>(Arrays.asList(elements))); + } + + /** + * Returns a new read-only set with the specified elements. + *

+ * If the set can be cast to {@link ImmutableSet, + * it will be cast, otherwise a new set will be created. + * + * @param elements the specified elements + * @param the element type + * @return read-only set with the specified elements + */ + public static ReadOnlySet copyOf(Iterable elements) { + if (elements instanceof ImmutableSet) return (ReadOnlySet) elements; + if (elements instanceof Collection) return new ReadOnlySetFacade<>(new HashSet<>((Collection) elements)); + var s = new HashSet(); + for (var e : elements) { + s.add(e); + } + return new ReadOnlySetFacade<>(s); + } + + /** + * Returns the same set wrapped or cast into a read-only set interface. + *

+ * If the set can be cast to a {@link ReadOnlySet}, it will be cast. + * + * @param elements the specified elements + * @param the element type + * @return read-only set with the specified elements + */ + public static ReadOnlySet asReadOnly(Set elements) { + return elements instanceof ReadOnlySet ? (ReadOnlySet) elements : new ReadOnlySetFacade<>(elements); + } +} diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/SizeLimitExceededException.java b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/exception/SizeLimitExceededException.java similarity index 95% rename from org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/SizeLimitExceededException.java rename to org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/exception/SizeLimitExceededException.java index d74276078..95ada644d 100644 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/readonly/SizeLimitExceededException.java +++ b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/exception/SizeLimitExceededException.java @@ -1,4 +1,5 @@ -package org.jhotdraw8.collection.readonly; +package org.jhotdraw8.icollection.exception; + /** * This exception is thrown when a method exceeds a size limit. diff --git a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlySequencedCollectionFacade.java b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/facade/ReadOnlySequencedCollectionFacade.java old mode 100755 new mode 100644 similarity index 88% rename from org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlySequencedCollectionFacade.java rename to org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/facade/ReadOnlySequencedCollectionFacade.java index 4632017cd..c2a4d9a74 --- a/org.jhotdraw8.collection/src/main/java/org.jhotdraw8.collection/org/jhotdraw8/collection/facade/ReadOnlySequencedCollectionFacade.java +++ b/org.jhotdraw8.icollection/src/main/java/org.jhotdraw8.icollection/org/jhotdraw8/icollection/facade/ReadOnlySequencedCollectionFacade.java @@ -2,14 +2,15 @@ * @(#)ReadOnlySequencedCollectionFacade.java * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. */ -package org.jhotdraw8.collection.facade; +package org.jhotdraw8.icollection.facade; + import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedCollection; -import org.jhotdraw8.collection.readonly.ReadOnlySequencedSet; -import org.jhotdraw8.collection.sequenced.SequencedSet; +import org.jhotdraw8.icollection.readonly.ReadOnlySequencedCollection; +import org.jhotdraw8.icollection.readonly.ReadOnlySequencedSet; import java.util.Iterator; +import java.util.SequencedSet; import java.util.function.IntSupplier; import java.util.function.Predicate; import java.util.function.Supplier; @@ -34,7 +35,7 @@ public ReadOnlySequencedCollectionFacade(@NonNull ReadOnlySequencedSet backin } public ReadOnlySequencedCollectionFacade(@NonNull SequencedSet backingSet) { - this(backingSet::iterator, () -> backingSet._reversed().iterator(), backingSet::size, + this(backingSet::iterator, () -> backingSet.reversed().iterator(), backingSet::size, backingSet::contains, backingSet::getFirst, backingSet::getLast); } diff --git a/org.jhotdraw8.os/pom.xml b/org.jhotdraw8.os/pom.xml index e870db45d..9b39a7000 100644 --- a/org.jhotdraw8.os/pom.xml +++ b/org.jhotdraw8.os/pom.xml @@ -50,6 +50,10 @@ ch.randelshofer org.jhotdraw8.collection + + ch.randelshofer + org.jhotdraw8.icollection + org.openjfx javafx-graphics diff --git a/org.jhotdraw8.os/src/main/java/org.jhotdraw8.os/module-info.java b/org.jhotdraw8.os/src/main/java/org.jhotdraw8.os/module-info.java index c3204cf55..8f6058774 100755 --- a/org.jhotdraw8.os/src/main/java/org.jhotdraw8.os/module-info.java +++ b/org.jhotdraw8.os/src/main/java/org.jhotdraw8.os/module-info.java @@ -12,6 +12,7 @@ requires transitive javafx.graphics; requires static org.jhotdraw8.annotation; requires transitive org.jhotdraw8.collection; + requires transitive org.jhotdraw8.icollection; exports org.jhotdraw8.os; exports org.jhotdraw8.os.macos; diff --git a/org.jhotdraw8.os/src/test/java/org.jhotdraw8.os/org/jhotdraw8/os/macos/MacOSPreferencesTest.java b/org.jhotdraw8.os/src/test/java/org.jhotdraw8.os/org/jhotdraw8/os/macos/MacOSPreferencesTest.java index a9835a123..e0e69e00a 100755 --- a/org.jhotdraw8.os/src/test/java/org.jhotdraw8.os/org/jhotdraw8/os/macos/MacOSPreferencesTest.java +++ b/org.jhotdraw8.os/src/test/java/org.jhotdraw8.os/org/jhotdraw8/os/macos/MacOSPreferencesTest.java @@ -6,7 +6,7 @@ package org.jhotdraw8.os.macos; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.MapEntries; +import org.jhotdraw8.icollection.MapEntries; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.TestFactory; diff --git a/org.jhotdraw8.svg/pom.xml b/org.jhotdraw8.svg/pom.xml index 18c40670c..21680527d 100644 --- a/org.jhotdraw8.svg/pom.xml +++ b/org.jhotdraw8.svg/pom.xml @@ -55,6 +55,10 @@ org.jhotdraw8.collection + ch.randelshofer + org.jhotdraw8.icollection + + org.junit.jupiter junit-jupiter test diff --git a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/module-info.java b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/module-info.java index 3548a02d4..60d38272b 100755 --- a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/module-info.java +++ b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/module-info.java @@ -18,6 +18,7 @@ requires transitive org.jhotdraw8.collection; requires transitive org.jhotdraw8.css; requires transitive org.jhotdraw8.draw; + requires org.jhotdraw8.icollection; exports org.jhotdraw8.svg.io; exports org.jhotdraw8.svg.gui; diff --git a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/AbstractSvgGradientFigure.java b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/AbstractSvgGradientFigure.java index 33dd99e88..92a6e854e 100755 --- a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/AbstractSvgGradientFigure.java +++ b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/AbstractSvgGradientFigure.java @@ -12,8 +12,6 @@ import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.MappedConverter; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.css.value.CssDefaultableValue; import org.jhotdraw8.css.value.CssSize; @@ -32,6 +30,8 @@ import org.jhotdraw8.draw.render.RenderContext; import org.jhotdraw8.fxcollection.typesafekey.NonNullKey; import org.jhotdraw8.fxcollection.typesafekey.SimpleNonNullKey; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import org.jhotdraw8.svg.css.SvgDefaultablePaint; import org.jhotdraw8.svg.text.SvgGradientUnits; diff --git a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgDefaultableFigure.java b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgDefaultableFigure.java index 981e7f7d7..90a75cad7 100644 --- a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgDefaultableFigure.java +++ b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgDefaultableFigure.java @@ -15,8 +15,6 @@ import javafx.scene.shape.StrokeType; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.css.converter.CssDoubleConverter; import org.jhotdraw8.css.converter.CssKebabCaseEnumConverter; @@ -34,6 +32,8 @@ import org.jhotdraw8.draw.figure.DefaultableFigure; import org.jhotdraw8.draw.key.DefaultableStyleableKey; import org.jhotdraw8.draw.render.RenderContext; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import org.jhotdraw8.svg.css.SvgDefaultablePaint; import org.jhotdraw8.svg.css.SvgPaintDefaulting; import org.jhotdraw8.svg.io.SvgFontFamilyConverter; @@ -50,10 +50,10 @@ import java.util.Objects; -import static org.jhotdraw8.collection.MapEntries.entry; -import static org.jhotdraw8.collection.MapEntries.linkedHashMap; -import static org.jhotdraw8.collection.MapEntries.of; -import static org.jhotdraw8.collection.MapEntries.ofEntries; +import static org.jhotdraw8.icollection.MapEntries.entry; +import static org.jhotdraw8.icollection.MapEntries.linkedHashMap; +import static org.jhotdraw8.icollection.MapEntries.of; +import static org.jhotdraw8.icollection.MapEntries.ofEntries; import static org.jhotdraw8.svg.io.SvgFontFamilyConverter.GENERIC_FONT_FAMILY_SANS_SERIF; /** diff --git a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgLinearGradientFigure.java b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgLinearGradientFigure.java index c7b16eba3..5fcccb134 100755 --- a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgLinearGradientFigure.java +++ b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgLinearGradientFigure.java @@ -10,12 +10,12 @@ import javafx.scene.paint.Stop; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.css.value.DefaultUnitConverter; import org.jhotdraw8.css.value.UnitConverter; import org.jhotdraw8.draw.key.CssSizeStyleableKey; import org.jhotdraw8.draw.render.RenderContext; +import org.jhotdraw8.icollection.immutable.ImmutableList; import org.jhotdraw8.svg.text.SvgGradientUnits; import java.util.ArrayList; diff --git a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgPolygonFigure.java b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgPolygonFigure.java index cfdc7a206..5aada7a38 100755 --- a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgPolygonFigure.java +++ b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgPolygonFigure.java @@ -12,8 +12,6 @@ import javafx.scene.shape.Polygon; import javafx.scene.transform.Transform; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.draw.css.value.CssRectangle2D; import org.jhotdraw8.draw.figure.AbstractLeafFigure; @@ -24,6 +22,8 @@ import org.jhotdraw8.draw.key.DoubleListStyleableKey; import org.jhotdraw8.draw.render.RenderContext; import org.jhotdraw8.geom.FXTransforms; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.awt.geom.AffineTransform; import java.awt.geom.Path2D; diff --git a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgPolylineFigure.java b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgPolylineFigure.java index 2c8e9c3b3..92296d1f3 100755 --- a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgPolylineFigure.java +++ b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgPolylineFigure.java @@ -12,8 +12,6 @@ import javafx.scene.shape.Polyline; import javafx.scene.transform.Transform; import org.jhotdraw8.annotation.NonNull; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.css.value.UnitConverter; import org.jhotdraw8.draw.css.value.CssRectangle2D; @@ -25,6 +23,8 @@ import org.jhotdraw8.draw.key.DoubleListStyleableKey; import org.jhotdraw8.draw.render.RenderContext; import org.jhotdraw8.geom.FXTransforms; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.awt.geom.AffineTransform; import java.awt.geom.Path2D; diff --git a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgRadialGradientFigure.java b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgRadialGradientFigure.java index 29c22147f..dbea93867 100755 --- a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgRadialGradientFigure.java +++ b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgRadialGradientFigure.java @@ -11,13 +11,13 @@ import javafx.scene.paint.Stop; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.css.value.DefaultUnitConverter; import org.jhotdraw8.css.value.UnitConverter; import org.jhotdraw8.draw.figure.Figure; import org.jhotdraw8.draw.key.CssSizeStyleableKey; import org.jhotdraw8.draw.render.RenderContext; +import org.jhotdraw8.icollection.immutable.ImmutableList; import org.jhotdraw8.svg.text.SvgGradientUnits; import java.util.ArrayList; diff --git a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgTransformableFigure.java b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgTransformableFigure.java index 48bf99817..9f9eb52f7 100755 --- a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgTransformableFigure.java +++ b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/figure/SvgTransformableFigure.java @@ -13,8 +13,6 @@ import javafx.scene.transform.Translate; import org.jhotdraw8.annotation.NonNull; import org.jhotdraw8.annotation.Nullable; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.draw.css.value.CssPoint2D; import org.jhotdraw8.draw.figure.Figure; import org.jhotdraw8.draw.figure.TransformCachingFigure; @@ -23,6 +21,8 @@ import org.jhotdraw8.draw.render.RenderContext; import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.geom.FXTransforms; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.util.ArrayList; import java.util.LinkedHashSet; diff --git a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/io/AbstractFXSvgWriter.java b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/io/AbstractFXSvgWriter.java index 5bbfc94b8..f419870ae 100755 --- a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/io/AbstractFXSvgWriter.java +++ b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/io/AbstractFXSvgWriter.java @@ -12,14 +12,33 @@ import javafx.scene.Node; import javafx.scene.Parent; import javafx.scene.image.ImageView; -import javafx.scene.layout.*; +import javafx.scene.layout.BackgroundFill; +import javafx.scene.layout.BorderStroke; +import javafx.scene.layout.BorderStrokeStyle; +import javafx.scene.layout.CornerRadii; +import javafx.scene.layout.Region; import javafx.scene.paint.Color; +import javafx.scene.paint.LinearGradient; import javafx.scene.paint.Paint; -import javafx.scene.paint.*; +import javafx.scene.paint.RadialGradient; +import javafx.scene.paint.Stop; +import javafx.scene.shape.Arc; +import javafx.scene.shape.ArcType; +import javafx.scene.shape.Circle; +import javafx.scene.shape.CubicCurve; +import javafx.scene.shape.Ellipse; +import javafx.scene.shape.FillRule; +import javafx.scene.shape.Line; +import javafx.scene.shape.Path; import javafx.scene.shape.Polygon; +import javafx.scene.shape.Polyline; +import javafx.scene.shape.QuadCurve; import javafx.scene.shape.Rectangle; +import javafx.scene.shape.SVGPath; import javafx.scene.shape.Shape; -import javafx.scene.shape.*; +import javafx.scene.shape.StrokeLineCap; +import javafx.scene.shape.StrokeLineJoin; +import javafx.scene.shape.StrokeType; import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.scene.text.TextAlignment; @@ -32,13 +51,18 @@ import org.jhotdraw8.base.converter.IdFactory; import org.jhotdraw8.base.converter.SimpleIdFactory; import org.jhotdraw8.base.converter.XmlNumberConverter; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.converter.CssDoubleConverter; import org.jhotdraw8.css.converter.CssListConverter; import org.jhotdraw8.draw.css.value.CssDimension2D; import org.jhotdraw8.fxbase.beans.AbstractPropertyBean; -import org.jhotdraw8.geom.*; +import org.jhotdraw8.geom.FXPreciseRotate; +import org.jhotdraw8.geom.FXRectangles; +import org.jhotdraw8.geom.FXShapes; +import org.jhotdraw8.geom.FXSvgPaths; +import org.jhotdraw8.geom.FXTransforms; +import org.jhotdraw8.geom.SvgPaths; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import org.jhotdraw8.svg.text.SvgPaintConverter; import org.jhotdraw8.svg.text.SvgTransformConverter; import org.jhotdraw8.xml.IndentingXMLStreamWriter; @@ -62,12 +86,19 @@ import java.awt.geom.Area; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; -import java.io.*; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.StringReader; +import java.io.Writer; import java.net.URI; import java.text.AttributedCharacterIterator; import java.text.AttributedString; +import java.util.ArrayList; +import java.util.Base64; +import java.util.Iterator; import java.util.List; -import java.util.*; +import java.util.Objects; import static org.jhotdraw8.draw.io.BitmapExportOutputFormat.fromFXImage; diff --git a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/io/FigureSvgTinyReader.java b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/io/FigureSvgTinyReader.java index df075aea1..9934f6032 100644 --- a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/io/FigureSvgTinyReader.java +++ b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/io/FigureSvgTinyReader.java @@ -10,9 +10,6 @@ import org.jhotdraw8.base.concurrent.CheckedRunnable; import org.jhotdraw8.base.converter.Converter; import org.jhotdraw8.base.converter.SimpleIdFactory; -import org.jhotdraw8.collection.MapEntries; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.collection.reflect.TypeToken; import org.jhotdraw8.css.converter.CssSizeConverter; import org.jhotdraw8.css.value.CssDefaultableValue; @@ -31,6 +28,9 @@ import org.jhotdraw8.fxcollection.typesafekey.Key; import org.jhotdraw8.fxcollection.typesafekey.MapAccessor; import org.jhotdraw8.fxcollection.typesafekey.NonNullKey; +import org.jhotdraw8.icollection.MapEntries; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import org.jhotdraw8.svg.css.SvgDefaultablePaint; import org.jhotdraw8.svg.css.text.SvgDefaultablePaintConverter; import org.jhotdraw8.svg.figure.SvgCircleFigure; diff --git a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/io/SvgFontFamilyConverter.java b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/io/SvgFontFamilyConverter.java index 55d7e6a70..7e8c255d5 100644 --- a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/io/SvgFontFamilyConverter.java +++ b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/io/SvgFontFamilyConverter.java @@ -9,12 +9,12 @@ import org.jhotdraw8.annotation.Nullable; import org.jhotdraw8.base.converter.IdResolver; import org.jhotdraw8.base.converter.IdSupplier; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; import org.jhotdraw8.css.converter.CssConverter; import org.jhotdraw8.css.parser.CssToken; import org.jhotdraw8.css.parser.CssTokenType; import org.jhotdraw8.css.parser.CssTokenizer; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.io.IOException; import java.text.ParseException; diff --git a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/text/SvgFontSizeConverter.java b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/text/SvgFontSizeConverter.java index db2ae99df..857f79b74 100755 --- a/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/text/SvgFontSizeConverter.java +++ b/org.jhotdraw8.svg/src/main/java/org.jhotdraw8.svg/org/jhotdraw8/svg/text/SvgFontSizeConverter.java @@ -20,9 +20,9 @@ import java.text.ParseException; import java.util.function.Consumer; -import static org.jhotdraw8.collection.MapEntries.entry; -import static org.jhotdraw8.collection.MapEntries.linkedHashMap; -import static org.jhotdraw8.collection.MapEntries.ofEntries; +import static org.jhotdraw8.icollection.MapEntries.entry; +import static org.jhotdraw8.icollection.MapEntries.linkedHashMap; +import static org.jhotdraw8.icollection.MapEntries.ofEntries; /** * Converts SVG font-size. diff --git a/org.jhotdraw8.teddy/src/main/java/org.jhotdraw8.teddy/org/jhotdraw8/teddy/TeddyActivity.java b/org.jhotdraw8.teddy/src/main/java/org.jhotdraw8.teddy/org/jhotdraw8/teddy/TeddyActivity.java index fe64984e2..c3d307ecd 100755 --- a/org.jhotdraw8.teddy/src/main/java/org.jhotdraw8.teddy/org/jhotdraw8/teddy/TeddyActivity.java +++ b/org.jhotdraw8.teddy/src/main/java/org.jhotdraw8.teddy/org/jhotdraw8/teddy/TeddyActivity.java @@ -20,12 +20,12 @@ import org.jhotdraw8.application.action.Action; import org.jhotdraw8.application.action.edit.RedoAction; import org.jhotdraw8.application.action.edit.UndoAction; -import org.jhotdraw8.collection.immutable.ImmutableMap; import org.jhotdraw8.fxbase.concurrent.FXWorker; import org.jhotdraw8.fxbase.concurrent.WorkState; import org.jhotdraw8.fxbase.control.TextInputControlUndoAdapter; import org.jhotdraw8.fxbase.undo.FXUndoManager; import org.jhotdraw8.fxcollection.typesafekey.Key; +import org.jhotdraw8.icollection.immutable.ImmutableMap; import org.jhotdraw8.teddy.action.FontAction; import org.jhotdraw8.teddy.action.FontableActivity; diff --git a/org.jhotdraw8.xml/pom.xml b/org.jhotdraw8.xml/pom.xml index dfcec30b1..e05492e88 100644 --- a/org.jhotdraw8.xml/pom.xml +++ b/org.jhotdraw8.xml/pom.xml @@ -76,5 +76,9 @@ ch.randelshofer org.jhotdraw8.fxbase + + ch.randelshofer + org.jhotdraw8.icollection + diff --git a/org.jhotdraw8.xml/src/main/java/org.jhotdraw8.xml/module-info.java b/org.jhotdraw8.xml/src/main/java/org.jhotdraw8.xml/module-info.java index 2c1c36497..5bfaab804 100755 --- a/org.jhotdraw8.xml/src/main/java/org.jhotdraw8.xml/module-info.java +++ b/org.jhotdraw8.xml/src/main/java/org.jhotdraw8.xml/module-info.java @@ -16,6 +16,7 @@ requires transitive org.jhotdraw8.css; requires transitive org.jhotdraw8.fxbase; requires transitive org.jhotdraw8.collection; + requires org.jhotdraw8.icollection; exports org.jhotdraw8.xml; exports org.jhotdraw8.xml.converter; diff --git a/org.jhotdraw8.xml/src/main/java/org.jhotdraw8.xml/org/jhotdraw8/xml/converter/XmlWordListConverter.java b/org.jhotdraw8.xml/src/main/java/org.jhotdraw8.xml/org/jhotdraw8/xml/converter/XmlWordListConverter.java index 46acebd61..9a979fec0 100755 --- a/org.jhotdraw8.xml/src/main/java/org.jhotdraw8.xml/org/jhotdraw8/xml/converter/XmlWordListConverter.java +++ b/org.jhotdraw8.xml/src/main/java/org.jhotdraw8.xml/org/jhotdraw8/xml/converter/XmlWordListConverter.java @@ -9,8 +9,8 @@ import org.jhotdraw8.base.converter.Converter; import org.jhotdraw8.base.converter.IdResolver; import org.jhotdraw8.base.converter.IdSupplier; -import org.jhotdraw8.collection.VectorList; -import org.jhotdraw8.collection.immutable.ImmutableList; +import org.jhotdraw8.icollection.VectorList; +import org.jhotdraw8.icollection.immutable.ImmutableList; import java.io.IOException; import java.nio.CharBuffer; diff --git a/org.jhotdraw8.xml/src/main/java/org.jhotdraw8.xml/org/jhotdraw8/xml/converter/XmlWordSetConverter.java b/org.jhotdraw8.xml/src/main/java/org.jhotdraw8.xml/org/jhotdraw8/xml/converter/XmlWordSetConverter.java index ddc130d59..67b4cf208 100755 --- a/org.jhotdraw8.xml/src/main/java/org.jhotdraw8.xml/org/jhotdraw8/xml/converter/XmlWordSetConverter.java +++ b/org.jhotdraw8.xml/src/main/java/org.jhotdraw8.xml/org/jhotdraw8/xml/converter/XmlWordSetConverter.java @@ -9,9 +9,9 @@ import org.jhotdraw8.base.converter.Converter; import org.jhotdraw8.base.converter.IdResolver; import org.jhotdraw8.base.converter.IdSupplier; -import org.jhotdraw8.collection.ChampSet; -import org.jhotdraw8.collection.VectorSet; -import org.jhotdraw8.collection.immutable.ImmutableSet; +import org.jhotdraw8.icollection.ChampSet; +import org.jhotdraw8.icollection.VectorSet; +import org.jhotdraw8.icollection.immutable.ImmutableSet; import java.io.IOException; import java.nio.CharBuffer; diff --git a/pom.xml b/pom.xml index 6a1d0edcc..cdf063cc2 100644 --- a/pom.xml +++ b/pom.xml @@ -397,6 +397,11 @@ ch.randelshofer + org.jhotdraw8.icollection + ${revision} + + + ch.randelshofer org.jhotdraw8.draw ${revision}